Output IP Address with ipconfig Findstr Ethernet Adapter
How many times have you entered ipconfig /all
at the command line to return a single IP address, then have to strain your eyes sifting through mostly unwanted networking info (subnet mask/gateway/DNS/mac address)? As a sysadmin, after rinsing and repeating this process nearly every day of your waking sysadmin life, this tends to lean towards the monotonous side. What I would like to propose is to declare an environment variable which utilizes native Windows CLI tools which strips out the information you don’t need while leaving the gold behind, the IP address. Create a short and easy environmental variable so that the command is easily repeatable with as few as five key strokes. If this doesn’t make sense to you yet, continue reading and it will.
Check out cmder (or ConEmu) if you are still using the normal command prompt as your primary terminal on Windows. Although the cmd.exe interface has improved since XP, I’m telling you right now that you will not regret it, and once you switch you won’t ever go back to plain cmd.exe.
Click here to download.
:: Output network adapter name and IP addresses using native commands only ipconfig /all | findstr /IR "ipv4 ethernet adapter" | findstr /IRV "description tunnel vpn dial bluetooth [2-9]:$" | findstr /LV "*" :: Using grep binary from gnuwin32 output only network adapter name and IP addresses ipconfig /all | grep -iE "ipv4|ethernet|adapter" | grep -iEv "description|tunnel|vpn|dial|bluetooth|[2-9]:$" | grep -iFv "connection*" :: And one more that yields the bare essentials (hostname, adapter name, MAC, IPv4, subnet, gateway, DNS) :: I purposefully excluded v6 addresses because I don't have a need, if you need then just omit it ipconfig /all | findstr -iv "ipv6 bluetooth Description DHCP Autoconfiguration Netbios routing wins node Connection-specific obtained expires disconnected"
Configure Environmental Variable
At the command prompt (hopefully you’re using cmder/conemu now) copy and paste this:
SET "ip=ipconfig /all | findstr /IR "ipv4 ethernet adapter" | findstr /IRV "description tunnel vpn dial bluetooth [2-9]:$" | findstr /LV "*""
This creates the envvar ip
. In order to call it, you will prefix and suffix the variable with the percent symbol. At the command-line simply type %ip%
and press return.
If you would rather configure/add/delete envvars using the GUI instead the follow these instructions:
key + R sysdm.cpl Advanced tab Environmental Variables button. It doesn’t really matter much if you define it as a User or System envvar, if you only have one user account, which I’m assuming you do.
Here are the results for each of the 3:
ipconfig /all | findstr /IR "ipv4 ethernet adapter" | findstr /IRV "description tunnel vpn dial bluetooth [2-9]:$" | findstr /LV "*"
Ethernet adapter Ethernet: IPv4 Address. . . . . . . . . . . : 10.10.10.74(Preferred) Ethernet adapter VMware Network Adapter VMnet1: IPv4 Address. . . . . . . . . . . : 192.168.134.1(Preferred) IPv4 Address. . . . . . . . . . . : 192.168.179.1(Preferred) Wireless LAN adapter Wi-Fi: IPv4 Address. . . . . . . . . . . : 10.10.10.56(Preferred)
ipconfig /all | grep -iE "ipv4|ethernet|adapter" | grep -iEv "description|tunnel|vpn|dial|bluetooth|[2-9]:$" | grep -iFv "connection*"
Ethernet adapter Ethernet: IPv4 Address. . . . . . . . . . . : 10.10.10.74(Preferred) Ethernet adapter VMware Network Adapter VMnet1: IPv4 Address. . . . . . . . . . . : 192.168.134.1(Preferred) IPv4 Address. . . . . . . . . . . : 192.168.179.1(Preferred) Wireless LAN adapter Wi-Fi: IPv4 Address. . . . . . . . . . . : 10.10.10.56(Preferred)
ipconfig /all | findstr -iv "ipv6 bluetooth Description DHCP Autoconfiguration Netbios routing wins node Connection-specific obtained expires disconnected"
Windows IP Configuration Host Name . . . . . . . . . . . . : visualblindfx Primary Dns Suffix . . . . . . . : DNS Suffix Search List. . . . . . : ad.blog.travisrunyard.us Ethernet adapter Ethernet: Physical Address. . . . . . . . . : 2C-4D-54-C8-0E-F5 IPv4 Address. . . . . . . . . . . : 10.10.10.74(Preferred) Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 10.10.10.1 DNS Servers . . . . . . . . . . . : 10.10.10.21 10.10.10.58 10.10.10.1 Wireless LAN adapter Local Area Connection* 1: Physical Address. . . . . . . . . : 34-F3-9A-78-35-7B Wireless LAN adapter Local Area Connection* 3: Physical Address. . . . . . . . . : 36-F3-9A-78-35-7A Ethernet adapter VMware Network Adapter VMnet1: Physical Address. . . . . . . . . : 00-50-56-C0-00-01 IPv4 Address. . . . . . . . . . . : 192.168.134.1(Preferred) Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1 fec0:0:0:ffff::2%1 fec0:0:0:ffff::3%1 Ethernet adapter VMware Network Adapter VMnet8: Physical Address. . . . . . . . . : 00-50-56-C0-00-08 IPv4 Address. . . . . . . . . . . : 192.168.179.1(Preferred) Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1 fec0:0:0:ffff::2%1 fec0:0:0:ffff::3%1 Wireless LAN adapter Wi-Fi: Physical Address. . . . . . . . . : 34-F3-9A-78-35-7A IPv4 Address. . . . . . . . . . . : 10.10.10.56(Preferred) Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 10.10.10.1 DNS Servers . . . . . . . . . . . : 10.10.10.21 10.10.10.58 10.10.10.1 Ethernet adapter Ethernet 2: Physical Address. . . . . . . . . : 00-FF-7D-9A-E5-0E
If you liked this article, please share it on a social network or click an advertisement to keep Sysinfo.io up and running.