Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

External IP address

18 views
Skip to first unread message

chawki...@gmail.com

unread,
Dec 14, 2006, 7:52:29 PM12/14/06
to
I use the following code to obtain the local IP address of my server:

proc ip:adr {} {
set me [socket -server xxx -myaddr [info hostname] 0]
set ip [lindex [fconfigure $me -sockname] 0]
close $me
return $ip
}

How would I obtain the external IP address?

Thanks,
CJ.

sleb...@gmail.com

unread,
Dec 15, 2006, 12:25:03 AM12/15/06
to

There's probably a page on the wiki for this. But my favourite method
is to query http://checkip.dyndns.com. You can do it with the http
package:

package require http
set f [http::geturl http://checkip.dyndns.com]
set raw [http::data $f]
http::cleanup $f
regexp -- {(\d+\.\d+\.\d+\.\d+)} $raw --> ip_address

puts $ip_address

Kaitzschu

unread,
Dec 15, 2006, 12:30:17 AM12/15/06
to
On Fri, 14 Dec 2006, sleb...@yahoo.com wrote:

> chawki...@gmail.com wrote:
> > How would I obtain the external IP address?
>
> There's probably a page on the wiki for this.

There indeed is, http://wiki.tcl.tk/3015
Not a walk in the park, if you ask me.

--
-Kaitzschu
s="TCL ";while true;do echo -en "\r$s";s=${s:1:${#s}}${s:0:1};sleep .1;done

Uwe Klein

unread,
Dec 15, 2006, 4:45:08 AM12/15/06
to
Which returns rubish if you sit behind a NAT gateway.

my workplace, ifconfig(eth1): 172.30.28.250

my workplace, your script: 84.144.214.55

which is the currently assigned IP of my DSL lease on
my gateway box.

uwe

sleb...@gmail.com

unread,
Dec 15, 2006, 5:31:55 AM12/15/06
to
Uwe Klein wrote:
> sleb...@yahoo.com wrote:
> > chawki...@gmail.com wrote:
> >
> >>I use the following code to obtain the local IP address of my server:
> >>
> >> proc ip:adr {} {
> >> set me [socket -server xxx -myaddr [info hostname] 0]
> >> set ip [lindex [fconfigure $me -sockname] 0]
> >> close $me
> >> return $ip
> >> }
> >>
> >>How would I obtain the external IP address?
> >
> >
> > There's probably a page on the wiki for this. But my favourite method
> > is to query http://checkip.dyndns.com. You can do it with the http
> > package:
> >
> > package require http
> > set f [http::geturl http://checkip.dyndns.com]
> > set raw [http::data $f]
> > http::cleanup $f
> > regexp -- {(\d+\.\d+\.\d+\.\d+)} $raw --> ip_address
> >
> > puts $ip_address
> >
> Which returns rubish if you sit behind a NAT gateway.
>
> my workplace, ifconfig(eth1): 172.30.28.250

Not what the OP wanted. The OP already has a script for this.

> my workplace, your script: 84.144.214.55

Which is exactly what the OP wanted.

Read carefully: the OP specified the "external" IP address which I
interpreted as the public IP, one attached to the NAT gateway.

sleb...@gmail.com

unread,
Dec 15, 2006, 5:44:38 AM12/15/06
to
sleb...@yahoo.com wrote:
> Uwe Klein wrote:
> > sleb...@yahoo.com wrote:
> > > chawki...@gmail.com wrote:
> > >>How would I obtain the external IP address?
> > >
> > > package require http
> > > set f [http::geturl http://checkip.dyndns.com]
> > > set raw [http::data $f]
> > > http::cleanup $f
> > > regexp -- {(\d+\.\d+\.\d+\.\d+)} $raw --> ip_address
> > >
> > > puts $ip_address
> > >
> >
> > my workplace, your script: 84.144.214.55
>
> Which is exactly what the OP wanted.
>
> Read carefully: the OP specified the "external" IP address which I
> interpreted as the public IP, one attached to the NAT gateway.

It should be noted however that even this may not get you the
"external" ip in question (the one belonging to the NAT gateway, if
any) but will instead get you an ip given by your HTTP proxy --
definitely not what you wanted since it is useless (the ip of the NAT
gateway is at least useful when used with port forwarding).

My ISP decided to install a transparent proxy one day without telling
anyone about it. The unfortunate part is that the proxy apparently has
a bug (or is over-eager) and ignores the HTTP header returned by
checkip.dyndns.com telling it not to cache the packet. So when I
queried the page it returned a cached version which contains an ip
address that belongs to someone else who accessed the page earlier
(probably my neighbor). Fortunately checkip.dyndns.com supports
querying via an alternate port which should solve the problem. I just
can't remember what port it is.

Uwe Klein

unread,
Dec 15, 2006, 5:43:50 AM12/15/06
to
sleb...@yahoo.com wrote:

> Which is exactly what the OP wanted.
>
> Read carefully: the OP specified the "external" IP address which I
> interpreted as the public IP, one attached to the NAT gateway.
>

My understanding of the OP was "That IP which is not the Loopback IF".

but you are right,

uwe

chawki...@gmail.com

unread,
Dec 15, 2006, 5:16:49 PM12/15/06
to

This worked like a charm. Very nice.
Thanks very much for the help.

CJ.

0 new messages