Solved

Getting My IP Address: Bouncing?

Posted on 2000-03-12
7
198 Views
Last Modified: 2012-05-04
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.
0
Comment
Question by:ljaques
7 Comments
 
LVL 3

Expert Comment

by:alien_life_form
ID: 2611814
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
 
LVL 8

Accepted Solution

by:
jhurst earned 50 total points
ID: 2614289
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
 
LVL 3

Expert Comment

by:alien_life_form
ID: 2615069
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ljaques
ID: 2615162
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
 
LVL 3

Expert Comment

by:alien_life_form
ID: 2615303
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
 
LVL 8

Expert Comment

by:jhurst
ID: 2616958
even on windows it is available, winipcfg does this.
0
 

Expert Comment

by:maalobs
ID: 2677562
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now