In Ruby, how does one get their IP octet without going through DNS?
Posted
by user30997
on Stack Overflow
See other posts from Stack Overflow
or by user30997
Published on 2008-12-18T22:23:20Z
Indexed on
2010/04/26
22:33 UTC
Read the original article
Hit count: 253
I can, on some of my systems, get my IP address (192.68.m.n format) by doing this:
addr = IPSocket::getAddress(Socket.gethostname())
...the trouble is that this only works if the name the local machine uses for itself is the name the DNS server associates with it.
How *&#( hard can it be for ruby to just return its primary interface's IP address? I have to do this in a platform-independant way or I'd just call ifconfig or ipconfig and parse it.
© Stack Overflow or respective owner