Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Just another Perl shrine
 
PerlMonks  

Simple IP Poster

by coolmichael (Deacon)
on Feb 27, 2001 at 13:18 UTC ( #61059=perlcraft: print w/ replies, xml ) Need Help??

   1: #!/usr/bin/perl -w
   2: 
   3: #run this from /etc/rc.d/rc.local to have your ip posted
   4: #to the net somewhere, so that when you start a machine, you
   5: #know where it is on the net.
   6: #comments, and suggestions are welcome.
   7: 
   8: use strict;
   9: use Net::FTP;
  10: 
  11: my $server="someserver.com";
  12: my $user="username";
  13: my $password="notarealpassword";
  14: my $dir="www";
  15: my $file="/tmp/ipinfo";
  16: 
  17: my $ftp;
  18: 
  19: `ifconfig > /tmp/ipinfo`;
  20: 
  21: $ftp=Net::FTP->new($server);
  22: $ftp->login($user, $password);
  23: $ftp->cwd($dir);
  24: $ftp->put($file);
  25: $ftp->quit;

Comment on Simple IP Poster
Download Code
Re: Simple IP Poster
by dws (Chancellor) on Feb 27, 2001 at 13:26 UTC
    Several problems here:
    1. If you're behind a proxy server that's doing network address translation, pushing an internal address into the outer world doesn't do you any good.
    2. If you're a "DMZ host" behind a broadband router that's getting its address via DHCP or PPPoE, you want that address, not the IP address of the machine that's running the script.
    3. The FTP protocol sends passwords in plaintext.

    It's safer to transfer the IP address via and HTTP GET or POST to a CGI that you control. In the case of a box behind a broadband router, the CGI will see the IP address assigned to the router. That's the IP address you'll need to connect to the DMZ host. The CGI can also record the time, so that you can tell how stale the IP address is.

      So basically, its a bad idea is what your saying? Sounds fair enough. I guess I could rewrite it with a CGI. That would be pretty simple, thanks for the suggestions. It works for my purposes.

        If you use a CGI to determine $ENV{'REMOTE_HOST'} make sure you're not using a proxy cache, either by configuring your script to do so or by being routed through one transparently.

        Some proxy servers send an X-Forwarded-For HTTP header, which you can retrieve using $ENV{'HTTP_X_FORWARDED_FOR'}, but the address contained within this variable may not be publicly accessible and is not guaranteed to be correct.

        It might be worth checking both these values, also checking for RFC 1918 IP addresses as a failsafe mechanism.

        This might be overkill, depending on your situation, but it's worth noting that the CGI approach isn't foolproof either.

        Also, you can't tell if anyone else is calling your CGI - you're relying on security through obscurity to ensure nobody else accesses your script.

Re: Simple IP Poster
by Hero Zzyzzx (Curate) on Mar 13, 2001 at 04:01 UTC

    Hey man, thanks for the little script. Gave me some ideas and worked on my box with no problems.

    I decided to run it daily, though, because sometimes my ADSL connection "refreshes" it's IP. The ifconfig command works perfectly, if you use pppoe, also.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlcraft [id://61059]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2014-04-16 07:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (418 votes), past polls