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.

 

CLI Tip:
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. Check out the screenshot.
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.sysinfo.io

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.

Share
Disqus Comments Loading...

Recent Posts

FreeNAS Error Creating Pool

command '('gpart', 'create', '-s', 'gpt', '/dev/da8')' returned non-zero exit status 1. If you get this error while trying to create… Read More

June 7, 2019 3:44 pm

Change Grub Default Boot Entry on Linux Mint

I'm dual booting Windows and Linux Mint on my laptop. The grub default is to boot into Linux Mint, however… Read More

April 23, 2019 7:45 pm

How to Reset Secure Channel On Active Directory Domain Controller

When you're a little too careless about virtualizing your domain controllers, cloning, migrating, backing up and restoring, returning from vacation… Read More

April 21, 2019 8:14 am

Run Systemd Script Before System Shutdown

I tried to retain the NGINX FastCGI cache and have it persist across system reboots instead of being ephemeral by… Read More

April 20, 2019 10:14 am

Learn Systemctl Usage to Manage Systemd Service in Linux

Systemd is new service manager for Linux. It's a replacement for all previous init systems (SysV/SysVinit & Ubuntu's Upstart) and… Read More

April 20, 2019 7:55 am

Force Delete Windows Server DHCP Failover Relationship

If you've found yourself here then chances are you messed up one of your domain controllers or at least one… Read More

April 20, 2019 5:54 am