• Linux
  • February 2019
    M T W T F S S
    « Jan   Mar »
     123
    45678910
    11121314151617
    18192021222324
    25262728  
  • Meta

  • Follow me on Twitter

  • Advertisements

ipinfo.sh

A while back I wrote a little script to display some basic IP information, public IP address, private IP address, default gateway, and DNS addresses. I had used the nmcli command piped through grep to display all of the IP4 information which also included route information which didn’t really interested me.

I didn’t particularly like the way the output looked so I took another look at the script to see if I could improve it. I did a little research and found a couple of different ways to get the local IP address and the default gateway. I still used nmcli to get the DNS addresses but found a way to use awk to get the just the addresses and display them nicely. The output looks so much better than before.

Just before I started on this little project I’d been watching a YouTube video covering some of the basics of using awk and I wondered if I could use awk to extract just the data I needed. I was able to use awk to pull and display all of the IP data except the public IP. Using awk, I didn’t need to use grep at all.

$ ipinfo.sh

IP Information
==============
Public IP:
	xx.xx.xx.xxx
Local IP:
	192.168.0.15/24
Default Gateway:
	192.168.0.1
DNS Servers:
	84.200.69.80
	84.200.70.40
	208.67.222.222

The script is on my GitHub Bash scripts repository.

Advertisements
%d bloggers like this: