tag:blogger.com,1999:blog-6167470039524068257.post5110984792890234236..comments2023-10-28T04:25:11.315-07:00Comments on Champion of Cyrodiil: Elaborate Linux Script for determining IPChampion Of Cyrodiilhttp://www.blogger.com/profile/06792737627887393792noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-6167470039524068257.post-69601363049943724822015-04-29T01:45:20.145-07:002015-04-29T01:45:20.145-07:00root@hop:~# ip -o -4 a | awk '{if ($2 ~ /[^lo]...root@hop:~# ip -o -4 a | awk '{if ($2 ~ /[^lo]/) print $2" "$4}' | cut -d/ -f1<br />eth0 172.18.196.236<br />virbr0 192.168.122.1<br />tun0 10.10.10.5<br />vboxnet0 10.20.0.1<br />vboxnet1 10.0.2.1<br />vboxnet2 10.0.2.1hophttps://www.blogger.com/profile/16738621347031802264noreply@blogger.comtag:blogger.com,1999:blog-6167470039524068257.post-30070771836571674732015-04-29T01:34:32.108-07:002015-04-29T01:34:32.108-07:00This comment has been removed by the author.hophttps://www.blogger.com/profile/16738621347031802264noreply@blogger.comtag:blogger.com,1999:blog-6167470039524068257.post-46137810272562671482015-02-18T10:30:24.628-08:002015-02-18T10:30:24.628-08:00Nice. I wasn't aware awk also supported if co...Nice. I wasn't aware awk also supported if conditions. The important thing to remember with both solutions is that you may have more than one adapter, so the if condition will need to be modified to fit the specific interface you're interested in. e.g.<br /><br />$ ifconfig -a<br />docker0 Link encap:Ethernet HWaddr 56:84:7a:fe:97:99 <br /> inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0<br /> UP BROADCAST MULTICAST MTU:1500 Metric:1<br /> RX packets:0 errors:0 dropped:0 overruns:0 frame:0<br /> TX packets:0 errors:0 dropped:0 overruns:0 carrier:0<br /> collisions:0 txqueuelen:0 <br /> RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)<br /><br />eth0 Link encap:Ethernet HWaddr fa:16:3e:e4:ca:cb <br /> inet addr:172.16.0.18 Bcast:172.16.255.255 Mask:255.255.0.0<br /> inet6 addr: fe80::f816:3eff:fee4:cacb/64 Scope:Link<br /> UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1<br /> RX packets:649673 errors:0 dropped:0 overruns:0 frame:0<br /> TX packets:398361 errors:0 dropped:0 overruns:0 carrier:0<br /> collisions:0 txqueuelen:1000 <br /> RX bytes:765872494 (765.8 MB) TX bytes:53054549 (53.0 MB)<br /><br />lo Link encap:Local Loopback <br /> inet addr:127.0.0.1 Mask:255.0.0.0<br /> inet6 addr: ::1/128 Scope:Host<br /> UP LOOPBACK RUNNING MTU:65536 Metric:1<br /> RX packets:59066 errors:0 dropped:0 overruns:0 frame:0<br /> TX packets:59066 errors:0 dropped:0 overruns:0 carrier:0<br /> collisions:0 txqueuelen:0 <br /> RX bytes:45734865 (45.7 MB) TX bytes:45734865 (45.7 MB)<br /><br />~$ ip -o -4 a | awk '{if ($2 ~ /[^lo]/) print $4}' | cut -d/ -f1<br />172.16.0.18<br />172.17.42.1<br /><br />Which one is actually eth0? Likely need another conditional check.<br /><br />Champion Of Cyrodiilhttps://www.blogger.com/profile/06792737627887393792noreply@blogger.comtag:blogger.com,1999:blog-6167470039524068257.post-56349799089607262402015-02-16T05:33:07.660-08:002015-02-16T05:33:07.660-08:00another way:
ip -o -4 a | awk '{if ($2 ~ /[^lo...another way:<br />ip -o -4 a | awk '{if ($2 ~ /[^lo]/) print $4}' | cut -d/ -f1<br />hophttps://www.blogger.com/profile/16738621347031802264noreply@blogger.com