ljaques
asked on
Getting My IP Address: Bouncing?
I want to obtain my computers IP address while I'm on the net. How do I achieve this in Perl? I am using Perl's sockets but see no way of achieving this thru there. I have seen programs like OMNIHTTP that bounce from another website to get the IP address but I have absolutely no idea how this works.
Thanls for any information.
Thanls for any information.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Greetings.
Of course, this implies you can run a cgi on a remote webserver. In that event, $ENV{REMOTE_ADDR} contains the ip of the connecting machine (which I believe may actually be the address of the proxy if any).
Cheers,
alf
Of course, this implies you can run a cgi on a remote webserver. In that event, $ENV{REMOTE_ADDR} contains the ip of the connecting machine (which I believe may actually be the address of the proxy if any).
Cheers,
alf
ASKER
All your comments have been great. I appreciate them.
Is there any way, though, to find out my IP address as opposed to a client? Is the only way for me to find out my ip address is to connect to some site that displays its ENV variables and then I must parse it for an IP address? It's just programs like OMNI HTTP seem to do it so effortlessly by bouncing off sites like Yahoo.
Is there any way, though, to find out my IP address as opposed to a client? Is the only way for me to find out my ip address is to connect to some site that displays its ENV variables and then I must parse it for an IP address? It's just programs like OMNI HTTP seem to do it so effortlessly by bouncing off sites like Yahoo.
Greetings.
The information you are looking for is always locally available to
your machine. On Linux, you could parse the output of route -n; on NT
of route PRINT. I am unsure wether win9x ships the route command , but
I think it has ipconfig which is equally good for your purpose (NT has
this one, too).
While I do not know what kind of beast OMNIHTTP is, I would speculate
that the bouncing process you describe takes advantage of some form of
(cookie? html?) encoding of the client address that web sites like
Yahoo send back in their response - for tracking purposes - after
extracting it with tecniques similar to the ones jhurst mentioned.
If that is indeed the case, this technique does not appear
particularly reliable: for one thing you could be actually be reading
the address of your provider's proxy/firewall (never mind if you have
or not configured one, many providers do transparent proxy); secondly,
you are depending on the way yahoo decides to code their pages, and
they may change it any time. At any rate, it will not be any more
reliable than the local protocol information.
Cheers,
alf
The information you are looking for is always locally available to
your machine. On Linux, you could parse the output of route -n; on NT
of route PRINT. I am unsure wether win9x ships the route command , but
I think it has ipconfig which is equally good for your purpose (NT has
this one, too).
While I do not know what kind of beast OMNIHTTP is, I would speculate
that the bouncing process you describe takes advantage of some form of
(cookie? html?) encoding of the client address that web sites like
Yahoo send back in their response - for tracking purposes - after
extracting it with tecniques similar to the ones jhurst mentioned.
If that is indeed the case, this technique does not appear
particularly reliable: for one thing you could be actually be reading
the address of your provider's proxy/firewall (never mind if you have
or not configured one, many providers do transparent proxy); secondly,
you are depending on the way yahoo decides to code their pages, and
they may change it any time. At any rate, it will not be any more
reliable than the local protocol information.
Cheers,
alf
even on windows it is available, winipcfg does this.
Here is a way to get your hosts current ip-address in Perl:
use Socket;
use Sys::Hostname;
my ($hostname, $addr, $address, $a, $b, $c, $d);
$hostname = hostname();
$addr = gethostbyname($hostname) or die "Couldn't resolve $hostname: $!\n";
($a,$b,$c,$d) = unpack('C4',$addr);
$address = "$a.$b.$c.$d";
print "My hostname: $hostname\n";
print "My address: $address\n";
use Socket;
use Sys::Hostname;
my ($hostname, $addr, $address, $a, $b, $c, $d);
$hostname = hostname();
$addr = gethostbyname($hostname) or die "Couldn't resolve $hostname: $!\n";
($a,$b,$c,$d) = unpack('C4',$addr);
$address = "$a.$b.$c.$d";
print "My hostname: $hostname\n";
print "My address: $address\n";
Perhaps you'll have to describe your environment and problem more clearly.
Getting IP addresses from 'listen' sockets is trivial - after accept, you'll get the remote IP as follows:
--from perlipc--
$paddr=accept(Client, Server);
my($port,$iaddr)=sockaddr_
my($name)=gethostbyaddr($a
---
This gives you the address of somebody connecting to you.
This doesn'apply to client side sockets: you need to know the address to create them in the first place.
But I think you're really after a different enterprise, one that probably requires no more than parsing the output of 'route' or somesuch.
Cheers,
alf