Perl script to retrieve an external IP address

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 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 HTML file with external IP address 
system ("wget -q"); 
open(FILE, '<index.html') || die("Could not open file!"); 
print "Your IP Address is: "; 
foreach (@raw_data) { 
	if (/((\d{1,3})(\.)){3}\d{1,3}/) { 
	print "$_\n"; 
# removing index.html 
system ("rm index.html");

Comments and Discussions
Linux Forum