[EMAIL PROTECTED] writes:

>>> Hi,
>>>    I'm trying to find my IP address from within Perl for eth0 and ppp0.
>>> Currently I run a regex on the output of ifconfig to extract his data -
>>> but, I'd like to do this from within Perl and it strikes me that this
>>> should be possible.
>>>
>>> HELP! ANYBODY!
>>>
>>
>>Well this module seems to do what you want already:
>>
>>http://search.cpan.org/~bluelines/Sys-HostIP-1.3.1/HostIP.pm
>>
>>I would say have a go at using it, or if you really want to re-invent
>>the wheel (maybe for a different kind of vehicle) have a look at the
> source.
>>
>>http://danconia.org
>
> This only tells me my eth0 IP address (192.168.0.10) which is my internal
> LAN IP address - which is not so useful, since I assigned this address! I'm
> trying to find out what my Internet or ppp0 IP address is. There must be an
> easy way of doing this.
>
> Any ideas

One surefire way is to use the dialog when your web browser hits a
page like: http://www.jtan.com/~reader/my_tricky_remote_addr.cgi.  It
generates a page displaying your IP as seen by the http page server.

This Source code produces what you see at above url.
#!/usr/bin/perl -w
  print "Content-type: text/html\n\n";
  $time = qx(date +"%m/%d/%y %w %H:%M:%S");
  $current_addr = $ENV{REMOTE_ADDR};
  if (! $current_addr){
     $current_addr = "Oops.. No address was obtained";
  }  
  print "<HTML>
  <HEAD><TITLE>my_addr</TITLE></HEAD>
  <BODY BGCOLOR=\"beige\">
  <HR>
  $time 
  <HR> 
  REMOTE_ADDR=$current_addr
  <HR>
  </BODY></HTML>";

One nice aspect of doing it this way is that you could view that
machines IP from anywhere by making the cgi write its output to file.

Hit the cgi from test machine then hit the generated webpage from
another address, you should see the test machines address displayed.

This code should do it:
#!/usr/bin/perl -w
  print "Content-type: text/html\n\n";
  $time = qx(date +"%m/%d/%y %w %H:%M:%S");
  open(FILE,"> ./my_tricky_remote_addr.html");
  $current_addr = $ENV{REMOTE_ADDR};
  if (! $current_addr){
     $current_addr = "Oops.. No address was obtained";
  }  
  print "<HTML>
  <HEAD><TITLE>my_addr</TITLE></HEAD>
  <BODY BGCOLOR=\"beige\">
  <HR>
  $time 
  <HR> 
  REMOTE_ADDR=$current_addr
  <HR>
  </BODY></HTML>";
  print FILE "<HTML>
  <HEAD><TITLE>my_addr</TITLE></HEAD>
  <BODY BGCOLOR=\"beige\">
  <HR>
  $time 
  <HR> 
  REMOTE_ADDR=$current_addr
  <HR>
  </BODY></HTML>";
  close(FILE);


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to