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.
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
> 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
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
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.
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.
> 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
This worked like a charm. Very nice.
Thanks very much for the help.
CJ.