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.
ljaquesAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
jhurstConnect With a Mentor Commented:
Those that bounce from a server use something like:

#!/usr/bin/perl

###########################################################################
#                     environment_variables.cgi                           #
#                                                                         #
# This script was written by Selena Sol (selena@eff.org                   #
# http://www.eff.org/~erict) having been inspired by countless other      #
# perl authors.  Feel free to copy, cite, reference, sample, borrow or    #
# plagiarize the contents.  However, please let me know where it goes so  #
# that I can at least watch and take part in the development of the       #
# memes. Information wants to be free, support public domain freware.     #
#                                                                         #
# Version: 2.0                                                            #
# Last Modified: 5-12-96                                                  #
# Description: This script will output all of the environment variables   #
#      available for use                                                  #  
# Usage: This script must be placed in a directory which allows cgi       #
#      executables and must have its permissions set such that the web    #
#      server has permission to execute it.                               #
#                                                                         #
###########################################################################

# First, print out the HTTP header.

  print "Content-type: text/html\n\n";

# Create a list of environment variables by gathering all the "keys" in the
# %ENV associative array.

  @environment_variables = keys (%ENV);

# For ever environment variable in the @environment_variables list, print
# the variable and then print its associated value.  Then quit.

  foreach $environment_variable (@environment_variables)
    {
    print "$environment_variable = $ENV{$environment_variable}<BR>\n";
    }
  exit;

There is a copy of this at my site:
http://209.245.58.156/env.cgi
0
 
alien_life_formCommented:
Greetings.

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_in($paddr);
my($name)=gethostbyaddr($addr,AF_INET);

---

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
0
 
alien_life_formCommented:
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
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
ljaquesAuthor Commented:
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.

0
 
alien_life_formCommented:
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
0
 
jhurstCommented:
even on windows it is available, winipcfg does this.
0
 
maalobsCommented:
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";
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.