Lots of people are behind (NAT) routers these days. If you're behind such a device and you want to see your external IP address (not the 192.168.... one), then feel free to use LWP or whatnot to fetch
this url and parse the simple document it returns. (But please don't use this in code that's distributed to more than a handlful of people. Put the attached code on your own server instead.)
---------- BEGIN /cgi-bin/ip_addr ----------
#!/bin/sh
cat << __EOI__
Content-Type: text/html
<html>
<head>
<title>ip address</title>
</head>
<body>
<p>Your ip address is $REMOTE_ADDR.</p>
</body>
</html>
__EOI__
----------- END /cgi-bin/ip_addr -----------
Update: Come to think of it, my script was meant for human eyes. If you wanted something for a script to read, it would be rewritten as:
---------- BEGIN /cgi-bin/ip_addr_as_text ----------
#!/bin/sh
cat << __EOI__
Content-Type: text/plain
$REMOTE_ADDR
__EOI__
----------- END /cgi-bin/ip_addr_as_text -----------
---------- BEGIN client code ----------
use LWP::Simple ();
$content = LWP::Simple::get("http://bla/cgi-bin/ip_addr_as_text");
die(...) unless (LWP::Simple::is_success());
chomp($content);
----------- END client code -----------
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.