Support Forums
Getting your external ip with perl - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Perl Programming Support (https://www.supportforums.net/forumdisplay.php?fid=31)
+---- Thread: Getting your external ip with perl (/showthread.php?tid=1949)

Pages: 1 2


Getting your external ip with perl - bsdpunk - 10-21-2009

You can get your external ip with perl by running this script...however, you have to install the LWP::Simple first. If you are on mac or linux you can simply go to the command line and type:
sudo cpan
You may have to set up cpan, for the most part you use all defaults, and choose servers near you.
then run
install LWP::Simple
cpan may ask you some more questions, just agree.

Then you can run this:

PHP Code:
#!/usr/bin/perl
use LWP::Simple;
$whyip qr/(Your IP address is \d+\.\d+\.\d+.\d+)/;
$content get("http://whatismyipaddress.com");
if(
$content =~ $whyip){
 print $&;


If you don't know your path to perl(#!/usr/bin/perl) then run it by typing
perl nameofscript.pl


RE: Getting your external ip with perl - flAmingw0rm - 10-26-2009

It's simple, thanks anyway. Smile


RE: Getting your external ip with perl - 0x80483fb - 12-12-2009

Nice. I can use this for my bot Smile.
But won't you need to backslash those dots and "d's"?
Edit: I've noticed this is not working, because of the useragent. It says: "it appears to be an automated script".


RE: Getting your external ip with perl - nextlive - 02-12-2010

Simple and nice Smile thanks for sharing this code...


RE: Getting your external ip with perl - JesusOfSuburbia - 05-03-2010

Thank's for the share man Oui


RE: Getting your external ip with perl - Julie - 05-09-2010

Simple but useful, thanks.


RE: Getting your external ip with perl - AceInfinity - 09-26-2010

and if you find a better website to get your IP address from then you can change the url in there (obviously) lol. I've noticed a few of these IP getting perl codes interpretted by others. It seems to be a popular area in this perl forum.


RE: Getting your external ip with perl - abel305 - 10-10-2010

Thanks alot for sharing this with us man.


RE: Getting your external ip with perl - Disease - 10-10-2010

(09-26-2010, 12:29 AM)Infinity Wrote: and if you find a better website to get your IP address from then you can change the url in there (obviously) lol. I've noticed a few of these IP getting perl codes interpretted by others. It seems to be a popular area in this perl forum.

Should you change the URI you would need to adjust the RegEx pattern to match. The pattern Bsdpunk created is specific to the site he has set by default.


RE: Getting your external ip with perl - Bursihido - 10-14-2010

good work thanks for sharing