Search This Blog

Wednesday, 9 February 2011

Perl script for getting Public IP from Linux


I used this script from LAN for getting my public IP which is obtained from ISP's DHCP server to my Modem

# cat getwanip.pl
#!/usr/bin/perl -w
#Owner                    :latheefp@gmail.com
#Purpose                  :Getting Public IP from Linux/Unix"
#Packages Required: Perl and wget
my $external_ip;
$external_ip = `wget -q -O - "http://checkip.dyndns.org"`;
if($external_ip =~ m/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/) {
        print "My Wan IP is $1\n";
}


The output will be similar to this.
[root@RH31 scripts]# ./getwanip.pl
My Wan IP is 178.74.XXX.221

No comments:

Post a Comment