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
#!/usr/bin/perl -w
#Purpose                  :Getting Public IP from Linux/Unix"
#Packages Required: Perl and wget
my $external_ip;
$external_ip = `wget -q -O - ""`;
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]# ./
My Wan IP is 178.74.XXX.221

No comments:

Post a Comment