RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux

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 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");

Share this linux post:

Submit Perl script to retrieve an external IP address in Delicious Submit Perl script to retrieve an external IP address in Digg Submit Perl script to retrieve an external IP address in FaceBook Submit Perl script to retrieve an external IP address in Google Bookmarks Submit Perl script to retrieve an external IP address in Stumbleupon Submit Perl script to retrieve an external IP address in Technorati Submit Perl script to retrieve an external IP address in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download