This simple perl script will print your external IP address assigned by you internet provider ( great for someone with dynamic IP address ).

First, we download a html file from ipchicken.com and then phrase this file to match for IP address in format X.X.X.X using regular expression.

Next, the script removes all unnecessary characters and prints your external IP address on the terminal. Lastly, the script removes previously downloaded index.html file.

get-external-ip.pl:

#!/usr/bin/perl 
 
# get HTML file with external IP address 
system ("wget -q http://ipchicken.com"); 
open(FILE, '<index.html') || die("Could not open file!"); 
 
print "Your IP Address is: "; 
 
@raw_data=<FILE>; 
foreach (@raw_data) { 
	if (/((\d{1,3})(\.)){3}\d{1,3}/) { 
	s/[^0-9.]*//g; 
	print "$_\n"; 
	} 
 } 
# removing index.html 
system ("rm index.html");

Free Linux eBooks

Linux Technical Writer

LinuxCareer, Casual, Volunteer, Home Based

Do you wish to join Linuxcareer.com project and find out how to be a technical writer? We are now looking for volunteers to help us write tutorials and share them with Linux community

  • Casual work from home
  • 10 articles / year

Any active Linuxcareer.com’s author will be entitled to following benefits:

  • actively participate in Linuxcareer.com’s decision making process
  • feedback and help

APPLY

Do you have the right skills?

Our IT Skills Watch page reflects an up to date IT skills demand leaning towards the Linux and Unix environment. We have considered a number of skills and operating systems.

See the result...

Linux Online Training

Learn to run Linux servers and prepare for LPI certification with Linux Academy. 104 available video lessons with PDF course notes with your own server!

Go to top