Last updated on November 11th, 2022 at 12:04 pm

Script that will find out your ip address. I have written 2 methods of finding ip address.

1] Using remote_addr() function

2] Using the environmental variable $ENV{REMOTE_ADDR} in perl.

Let us take a look at how the script looks. The remote_addr() uses CGI module.

#!/usr/local/bin/perl -W
use strict;
use CGI;
my $q = CGI->new();
print $q->header().$q->h3('IP address using regular method').$q->remote_addr()."\n";
print $q->h3('IP address using much more easier method');
my $rem_ip = $ENV{REMOTE_ADDR};
print $rem_ip;

Since the second method shown above is just grabbing ip address from perl environmental variable there is no need of calling CGI module. This is much easier method without any complications.

Make sure to modify interpreter /usr/local/bin/perl with your perl binary location.

Leave a Reply

Your email address will not be published. Required fields are marked *