Skip to content

标题: Win10获取本机及网关IP、MAC

1) 获取本机IP地址

chcp 437

ipconfig ipconfig | findstr IPv4 ipconfig /all | findstr "Description IPv4" (推荐) netsh interface ip show addresses | findstr IP

2) 获取本机MAC地址

chcp 437

ipconfig /all | findstr Description ipconfig /all | findstr /C:"Physical Address" ipconfig /all | findstr "Description Physical" (推荐) getmac getmac /v /fo list

3) 获取网关IP地址

chcp 437

netstat -nr | findstr "0.0.0.0" route print 0.0.0.0 -4 route print 0.0.0.0 -4 | findstr "0.0.0.0" (推荐) netsh interface ipv4 show route | findstr "0.0.0.0" (Get-NetRoute | Where-Object { $_.DestinationPrefix -eq '0.0.0.0/0' }).NextHop

4) 获取网关MAC地址

chcp 437

ping -n 1

arp -a (推荐) Get-NetNeighbor -IPAddress Get-NetNeighbor -IPAddress (Get-NetRoute | Where-Object { $_.DestinationPrefix -eq '0.0.0.0/0' }).NextHop reg.exe query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Nla\Cache\Intranet" (需管理员权限)