Retrieving External IP 
Author Message
 Retrieving External IP

I'm attempting to write a small script that retrieves a servers
external IP adress, but I keep comming up with it's subnet IP, any
suggestion on how to grab the external IP? Thank you much :)

Here's the Code for returning the the IP from the hostname:

host = Socket.gethostname
IP = IPSocket.getaddress(host)



Sun, 31 Oct 2004 05:35:05 GMT  
 Retrieving External IP

Quote:

> I'm attempting to write a small script that retrieves a servers
> external IP adress, but I keep comming up with it's subnet IP, any
> suggestion on how to grab the external IP? Thank you much :)

> Here's the Code for returning the the IP from the hostname:

> host = Socket.gethostname
> IP = IPSocket.getaddress(host)

Do you know the name of the external interface?  It may be different from
what's returned by hostname.


irb(main):001:0> require 'socket'
true
irb(main):002:0> packed_ip = Socket.gethostbyname('www.stok.co.uk')[3]
"??K5"
irb(main):003:0> packed_ip.unpack('C*').join('.')
"209.251.75.53"

(though I'm sure there must be an ntoa style function to do the packed
4 bytes -> String somewhere...)


www.stok.co.uk is an alias for stok.co.uk.
stok.co.uk has address 209.251.75.53

Hope this helps,

Mike

--

http://www.stok.co.uk/~mike/       | GPG PGP Key      1024D/059913DA

http://www.exegenix.com/           |                  75D2 9EC4 C1C0 0599 13DA



Sun, 31 Oct 2004 23:18:40 GMT  
 Retrieving External IP

Quote:


>> I'm attempting to write a small script that retrieves a servers
>> external IP adress, but I keep comming up with it's subnet IP, any
>> suggestion on how to grab the external IP? Thank you much :)

>> Here's the Code for returning the the IP from the hostname:

>> host = Socket.gethostname
>> IP = IPSocket.getaddress(host)

> Do you know the name of the external interface?  It may be different from
> what's returned by hostname.

Ignore me, plugging the right hostname into IPSocket.getaddress(host) works
and does all that conversion behind the scenes :-(

Mike

--

http://www.stok.co.uk/~mike/       | GPG PGP Key      1024D/059913DA

http://www.exegenix.com/           |                  75D2 9EC4 C1C0 0599 13DA



Sun, 31 Oct 2004 23:21:23 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Retrieve IP number

2. retrieving my ip address

3. Retrieve external wm event

4. Getting the external IP (behind a router)

5. How to do IP clock balance with external clock

6. ip vers nom et nom vers ip

7. IP v6 instead of IP v4??

8. Anyway to get the server ip address not the browser ip address

9. External link errors when using external Catalyst SocketTools Library Edition 2.15 dll

10. retrieving file data from an external server - where to start?

11. Get to know my external IP adress from Ruby?

12. Retrieving the name of defined operator operands

 

 
Powered by phpBB® Forum Software