The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music.
What if your system has no free entries in its process table and you are *desperately* in need of your IPv4? This can happen… in some planets.
Here's a version for Linux without any fork()s, in the major shells that support string slicing/substrings. In some proud ~220 characters.
bash/ksh:
iface=eth0; while read Iface x x x x x x x x x x x x x SpecDst x; do [ "$Iface" = $iface ] && for i in 6 4 2 0; do echo -n $((0x${SpecDst:i:2})); ((i==0)) || echo -n .; done && echo && break; done < /proc/net/rt_cache
zsh:
iface=eth0; while read Iface x x x x x x x x x x x x x SpecDst x; do [ "$Iface" = $iface ] && for i in 7 5 3 1; do echo -n $((0x${SpecDst[i,i+1]})); ((i==1)) || echo -n .; done && echo && break; done < /proc/net/rt_cache
I wonder if this is easier to read from any other place than the routing cache.
I am being sponsored by Syntress! They bought me an amazing dedicated server to run catonmat on. If you're looking web services, I highly recommend the Syntress guys!
Education Sponsors
I am being sponsored by A-Writer! If you ever need help with essay writing, look no further than A-Writer! They will help you with your writing in as quickly as 3 hours!
What if your system has no free entries in its process table and you are *desperately* in need of your IPv4? This can happen… in some planets.
Here's a version for Linux without any fork()s, in the major shells that support string slicing/substrings. In some proud ~220 characters.
bash/ksh:
iface=eth0; while read Iface x x x x x x x x x x x x x SpecDst x; do [ "$Iface" = $iface ] && for i in 6 4 2 0; do echo -n $((0x${SpecDst:i:2})); ((i==0)) || echo -n .; done && echo && break; done < /proc/net/rt_cachezsh:
iface=eth0; while read Iface x x x x x x x x x x x x x SpecDst x; do [ "$Iface" = $iface ] && for i in 7 5 3 1; do echo -n $((0x${SpecDst[i,i+1]})); ((i==1)) || echo -n .; done && echo && break; done < /proc/net/rt_cacheI wonder if this is easier to read from any other place than the routing cache.
Cheers.
Reply To This Comment