Skip to content

Instantly share code, notes, and snippets.

@sean-kang
Created November 22, 2013 03:54
Show Gist options
  • Select an option

  • Save sean-kang/7594601 to your computer and use it in GitHub Desktop.

Select an option

Save sean-kang/7594601 to your computer and use it in GitHub Desktop.
Example: getIpAddresses
SeanMac:temp sean$ cat test-ip
eth0 Link encap:Ethernet HWaddr 45:d3:49:60:f3:0b
inet addr:151.242.64.171 Bcast:178.22.71.255 Mask:255.255.248.0
inet6 addr: fe80::20c3:b4ff:fe6b:1fbb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:165709690 errors:0 dropped:0 overruns:0 frame:0
TX packets:17210384 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:20384657573 (20.3 GB) TX bytes:5304687858 (5.3 GB)
eth1 Link encap:Ethernet HWaddr 45:d3:49:60:f3:0b
inet addr:34.66.178.22 Bcast:178.22.71.255 Mask:255.255.248.0
inet6 addr: fe80::20c3:b4ff:fe6b:1fbb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:165709690 errors:0 dropped:0 overruns:0 frame:0
TX packets:17210384 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:20384657573 (20.3 GB) TX bytes:5304687858 (5.3 GB)
eth2 Link encap:Ethernet HWaddr 45:d3:49:60:f3:0b
inet addr:169.254.169.254 Bcast:178.22.71.255 Mask:255.255.248.0
inet6 addr: fe80::20c3:b4ff:fe6b:1fbb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:165709690 errors:0 dropped:0 overruns:0 frame:0
TX packets:17210384 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:20384657573 (20.3 GB) TX bytes:5304687858 (5.3 GB)
eth3 Link encap:Ethernet HWaddr 45:d3:49:60:f3:0b
inet addr:30.44.169.254 Bcast:178.22.71.255 Mask:255.255.248.0
inet6 addr: fe80::20c3:b4ff:fe6b:1fbb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:165709690 errors:0 dropped:0 overruns:0 frame:0
TX packets:17210384 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:20384657573 (20.3 GB) TX bytes:5304687858 (5.3 GB)
eth4 Link encap:Ethernet HWaddr 45:d3:49:60:f3:0b
inet addr:20.169.254.38 Bcast:178.22.71.255 Mask:255.255.248.0
inet6 addr: fe80::20c3:b4ff:fe6b:1fbb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:165709690 errors:0 dropped:0 overruns:0 frame:0
TX packets:17210384 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:20384657573 (20.3 GB) TX bytes:5304687858 (5.3 GB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:180322030 errors:0 dropped:0 overruns:0 frame:0
TX packets:180322030 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:54830774142 (54.8 GB) TX bytes:54830774142 (54.8 GB)
SeanMac:temp sean$ cat test-ip | grep -o -E 'inet addr:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | cut -d':' -f2 |grep -v -E '^127' | grep -v -E '^169\.254'
151.24.64.171
34.66.178.22
30.44.169.254
20.169.254.38
SeanMac:temp sean$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment