You're replying to a comment by redondos.

redondos Permalink
October 22, 2008, 19:08

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.

Cheers.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the first letter of your name: (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.