|
本帖最后由 窄口牛 于 2020-1-16 19:33 编辑
思路是这样的,tracert本地dns,取第一个值得到网关,然后ipconfig /all,得到网关和mac,然后将ip,网关,mac输出到计算机名的文本中。
因为一般单位管理都是要管外网的,所以这个思路应该成立。
获取有效网络信息.rar
(1.65 KB, 下载次数: 92)
更新为无须第三方版
NT6
- @echo off
- Setlocal enabledelayedexpansion
- wget -O temp "http://ip.chinaz.com/getip.aspx"
- cls
- for /f "tokens=2 delims='" %%i in (temp) do set result=%%i
- del temp 2>nul
- for /f "tokens=8 delims= " %%a in ('tracert -d 114.114.114.114') do echo %%a>>temp1
- for /f "delims=" %%i in ('ipconfig /all') do (
- call,set t=%%i
- call,echo %%t: =%%>>temp
- )
- for /f "tokens=1,3 delims=:" %%a in ('findstr ^/n ^/g:temp1 temp ^|find "默认网关"') do set Line=%%a&set Gateway=%%b
- set /a a=%Line%-9
- set /a b=%Line%-8
- set /a c=%Line%-7
- set /a d=%Line%-6
- set /a e=%Line%-4
- set /a f=%Line%-3
- set /a g=%Line%-2
- set /a h=%Line%-1
- set /a i=%Line%+1
- set /a j=%Line%+3
- set /a k=%Line%+4
- set /a l=%Line%+5
- echo 外网IP是: %result%
- for /f "tokens=1,2,3 delims=:" %%a in ('findstr /N . temp ^|findstr /b "%i%"') do echo %%b>temp2
- for /f "tokens=1 delims=." %%a in ('type temp2') do (set ans=%%a&del temp2)
- IF /I "%ans%" EQU "DHCP服务器" (
- for /f "tokens=1,3 delims=:" %%a in ('findstr /N . temp ^|findstr /b "%a%"') do (echo 网卡名称:%%b)
- for /f "tokens=1,3 delims=:" %%a in ('findstr /N . temp ^|findstr /b "%b%"') do (echo MCA地址:%%b)
- for /f "tokens=1,3 delims=:" %%a in ('findstr /N . temp ^|findstr /b "%e%"') do (echo IP地址为:%%b)
- for /f "tokens=1,3 delims=:" %%a in ('findstr /N . temp ^|findstr /b "%f%"') do (echo 子网掩码:%%b)
- echo 默认网关:%Gateway%
- for /f "tokens=1,3 delims=:" %%a in ('findstr /N . temp ^|findstr /b "%k%"') do (echo 首选DNS:%%b)
- for /f "tokens=1,2 delims=:" %%a in ('findstr /N . temp ^|findstr /b "%l%"') do (echo 备用DNS:%%b)
- del temp
- echo 下面是出网路由路径
- type temp1
- del temp1
- ) ELSE (
- for /f "tokens=1,3 delims=:" %%a in ('findstr /N . temp ^|findstr /b "%c%"') do (echo 网卡名称:%%b)
- for /f "tokens=1,3 delims=:" %%a in ('findstr /N . temp ^|findstr /b "%d%"') do (echo MCA地址:%%b)
- for /f "tokens=1,3 delims=:" %%a in ('findstr /N . temp ^|findstr /b "%g%"') do (echo IP地址为:%%b)
- for /f "tokens=1,3 delims=:" %%a in ('findstr /N . temp ^|findstr /b "%h%"') do (echo 子网掩码:%%b)
- echo 默认网关:%Gateway%
- for /f "tokens=1,3 delims=:" %%a in ('findstr /N . temp ^|findstr /b "%j%"') do (echo 首选DNS:%%b)
- for /f "tokens=1,2 delims=:" %%a in ('findstr /N . temp ^|findstr /b "%k%"') do (echo 备用DNS:%%b)
- del temp
- echo 下面是出网路由路径
- type temp1
- del temp1
- )
- pause>nul
复制代码
NT5- @echo off
- Setlocal enabledelayedexpansion
- wget -O temp "http://ip.chinaz.com/getip.aspx"
- cls
- for /f "tokens=2 delims='" %%i in (temp) do set result=%%i
- del temp 2>nul
- for /f "skip=2 tokens=8 delims= " %%a in ('tracert -d 114.114.114.114') do echo %%a>>temp1
- for /f "delims=" %%i in ('ipconfig /all') do (
- SET /a n+=1
- call,set t=%%i
- call,echo !n!:%%t: =%%>>temp
- )
- for /f "tokens=1,2,3 delims=:" %%a in ('findstr /G:temp1 temp ^|find "DefaultGateway"') do (
- set Line=%%a&set Gateway=%%c
- )
- set /a a=%Line%-6
- set /a b=%Line%-5
- set /a c=%Line%-4
- set /a d=%Line%-2
- set /a e=%Line%-1
- set /a f=%Line%+1
- set /a g=%Line%+2
- set /a h=%Line%+3
- echo 外网IP是: %result%
- for /f "tokens=1,2,3 delims=:" %%a in ('findstr /B "%f%" temp') do echo %%b>temp2
- for /f "tokens=1 delims=." %%a in ('type temp2') do (set ans=%%a&del temp2)
- if /i "%ans%" EQU "DHCPServer" (
- for /f "tokens=1,3 delims=:" %%a in ('findstr /B "%a%" temp') do (echo 网卡名称:%%b)
- for /f "tokens=1,3 delims=:" %%a in ('findstr /B "%b%" temp') do (echo MCA地址:%%b)
- for /f "tokens=1,3 delims=:" %%a in ('findstr /B "%d%" temp') do (echo IP地址为:%%b)
- for /f "tokens=1,3 delims=:" %%a in ('findstr /B "%e%" temp') do (echo 子网掩码:%%b)
- echo 默认网关:%Gateway%
- for /f "tokens=1,3 delims=:" %%a in ('findstr /B "%g%" temp') do (echo 首选DNS:%%b)
- for /f "tokens=1,2 delims=:" %%a in ('findstr /B "%h%" temp') do (echo 备用DNS:%%b)
- del temp
- echo 下面是出网路由路径
- type temp1
- del temp1
- ) ELSE (
- for /f "tokens=1,3 delims=:" %%a in ('findstr /B "%b%" temp') do (echo 网卡名称:%%b)
- for /f "tokens=1,3 delims=:" %%a in ('findstr /B "%c%" temp') do (echo MCA地址:%%b)
- for /f "tokens=1,3 delims=:" %%a in ('findstr /B "%d%" temp') do (echo IP地址为:%%b)
- for /f "tokens=1,3 delims=:" %%a in ('findstr /B "%e%" temp') do (echo 子网掩码:%%b)
- echo 默认网关:%Gateway%
- for /f "tokens=1,3 delims=:" %%a in ('findstr /B "%f%" temp') do (echo 首选DNS:%%b)
- for /f "delims=" %%a in ('findstr /B "%g%" temp') do (echo 备用DNS:%%a)
- del temp
- echo 下面是出网路由路径
- type temp1
- del temp1
- )
- pause>nul
复制代码
|
|