Unix/Linux
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs Unix/Linux

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old June 4th, 2006, 07:30 AM
Dave Farrance
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

I'm looking for a reasonably future-proof way to find the IP address of
a machine as seen from the Internet.

This worked once but not now. It was probably removed due to excessive
traffic:

wget 2>/dev/null

suggestions please?

Has any organisation decided to save the world and provide a
script-parseable IP address of the requesting machine?

--
Dave Farrance

Reply With Quote
  #2  
Old June 4th, 2006, 09:30 AM
Michael Heiming
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

In comp.unix.shell Dave Farrance <DaveFarrance@omitthisyahooandthis.co.uk>:
I'm looking for a reasonably future-proof way to find the IP address of
a machine as seen from the Internet.

This worked once but not now. It was probably removed due to excessive
traffic:
>

wget 2>/dev/null

suggestions please?

Has any organisation decided to save the world and provide a
script-parseable IP address of the requesting machine?

There are numerous if you can't find it out from the inside:

lynx -dump \
| awk '/is:/{print $NF}'

Though there's no guarantee if this won't change.

--
Michael Heiming (X-PGP-Sig GPG-Key ID: EDD27B94)
mail: echo zvpunry@urvzvat.qr | perl -pe 'y/a-z/n-za-m/'
#bofh excuse 95: Pentium FDIV bug

Reply With Quote
  #3  
Old June 4th, 2006, 10:10 AM
Bill Marcum
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

["Followup-To:" header set to comp.unix.shell.]
Sun, 04 Jun 2006 10:57:16 GMT, Dave Farrance
<DaveFarrance@MiTTHiSyahooANDTHiS.co.ukwrote:
I'm looking for a reasonably future-proof way to find the IP address of
a machine as seen from the Internet.
>

This worked once but not now. It was probably removed due to excessive
traffic:
>

wget 2>/dev/null
>

suggestions please?
>

Has any organisation decided to save the world and provide a
script-parseable IP address of the requesting machine?
>

ifconfig


--
The sum of the intelligence of the world is constant. The population is,
of course, growing.

Reply With Quote
  #4  
Old June 4th, 2006, 11:30 AM
Kenny McCormack
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

In article <em2bl3-je3.ln1@don.localnet>,
Bill Marcum <bmarcum@iglou.comwrote:
>["Followup-To:" header set to comp.unix.shell.]

Sun, 04 Jun 2006 10:57:16 GMT, Dave Farrance
<DaveFarrance@MiTTHiSyahooANDTHiS.co.ukwrote:
>I'm looking for a reasonably future-proof way to find the IP address of
>a machine as seen from the Internet.


>ifconfig


Every question has an answer that is simple, obvious, straightforward, and

WRNG!

The whole point is that nowadays most machines are behind some kind of
NAT/firewall and so the "real" IP address is not the one that the
NIC is configured to.

To the P: If you can FTP to somewhere, try "quote stat".


Reply With Quote
  #5  
Old June 4th, 2006, 11:30 AM
Dave Farrance
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

Bill Marcum <bmarcum@iglou.comwrote:

>ifconfig


Yeah but I wanted the address as seen by the Internet rather than one
that might be assigned by a local network router.

--
Dave Farrance

Reply With Quote
  #6  
Old June 4th, 2006, 11:30 AM
Dave Farrance
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

Michael Heiming <michael+USENET@www.heiming.dewrote:

>lynx -dump \

| awk '/is:/{print $NF}'

>Though there's no guarantee if this won't change.


Thanks, that works. I guess that it's the best that can be expected,
even if change is odds-on in the next few years. I've searched out a
few more sites that respond similarly:

lynx -dump http://www.formyip.com/ | awk '/IP is/{print $NF}'

lynx -dump http://www.showipaddress.com/ \
| awk '/IP address:/{print $NF}'

lynx -dump \
| awk '/current IP/{print $NF}'

lynx -dump \
| awk '/IP address is/{print $NF}'

lynx -dump \
| awk '/REMTE_ADDR/{print $2}'

--
Dave Farrance

Reply With Quote
  #7  
Old June 4th, 2006, 01:10 PM
Dave Farrance
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

gazelle@xmission.xmission.com (Kenny McCormack) wrote:

>To the P: If you can FTP to somewhere, try "quote stat".


Another interesting alternative. I guess this is a bit fragile because
it's dependent on the syntax of the current ftp for Linux.

#!/bin/bash
{
ftp -inuv <<eof
open ftp.proxad.net
user anonymous xx@xx.invalid
quote stat
quit
eof
} | awk '/ Connected to/{print $NF}'

--
Dave Farrance

Reply With Quote
  #8  
Old June 4th, 2006, 01:10 PM
Tim Heaney
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

Michael Heiming <michael+USENET@www.heiming.dewrites:
>

In comp.unix.shell Dave Farrance <DaveFarrance@omitthisyahooandthis.co.uk>:
>I'm looking for a reasonably future-proof way to find the IP address of
>a machine as seen from the Internet.
>
>This worked once but not now. It was probably removed due to excessive
>traffic:
>>

>wget 2>/dev/null
>
>suggestions please?
>
>Has any organisation decided to save the world and provide a
>script-parseable IP address of the requesting machine?
>

There are numerous if you can't find it out from the inside:
>

lynx -dump \
| awk '/is:/{print $NF}'
>

Though there's no guarantee if this won't change.

I think WhatIsMyIP.com is the most obvious one, but there's no
guarantee this won't change either. It's been my experience that the
plain text emitted by lynx -dump changes with upgrades to lynx
too. Since it's not that hard to parse the HTML itself, something like

perl -MLWP::Simple -le '$_=get q(http://www.whatismyip.com/); \
print $1 if /Your IP Is ((\d{1,3}\.){3}\d{1,3})/'

might be slightly less fragile than

lynx -dump http://whatismyip.com | awk '/Your IP Is/{print $NF}'

Tim

Reply With Quote
  #9  
Old June 4th, 2006, 01:50 PM
Dave Farrance
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

Tim Heaney <theaney@gmail.comwrote:

>I think WhatIsMyIP.com is the most obvious one, but there's no
>guarantee this won't change either. It's been my experience that the
>plain text emitted by lynx -dump changes with upgrades to lynx
>too. Since it's not that hard to parse the HTML itself, something like
>

perl -MLWP::Simple -le '$_=get q(http://www.whatismyip.com/); \
print $1 if /Your IP Is ((\d{1,3}\.){3}\d{1,3})/'

Thanks. I guess that using PERL is a bit more elegant than Lynx because
it's more likely to be installed. However, despite the lynx -dump
varying somewhat, it's output does make the subsequent parsing easier.
I tried the above script on the other websites that I'd found and it
was commonly stymied by embedded html tags - and the IP address
commonly appearing on the *next* line of the HTML source code even
though it was on the same line when the HTML was interpreted. It found
one other site that it worked with:

perl -MLWP::Simple -le '$_=get q(http://www.formyip.com/); \
print $1 if /IP is ((\d{1,3}\.){3}\d{1,3})/'

--
Dave Farrance

Reply With Quote
  #10  
Old June 4th, 2006, 01:50 PM
Lew Pitcher
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

PGP SIGNED MESSAGE
Hash: SHA1

Dave Farrance wrote:
I'm looking for a reasonably future-proof way to find the IP address of
a machine as seen from the Internet.

FWIW, I put together some automation, and used the 'free' personal webpage
provided by my ISP to give myself a 'rendesvous' site and redirect webpage.
You can find the details in an article I wrote for Linux Gazette issue 104
().

HTH
- --
Lew Pitcher

Master Codewright & JAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
PGP SIGNATURE
Version: GnuPG v1.4.2.2 (GNU/Linux)


mFIn1TVR/WZMv76/oYL3Ncw=
=
PGP SIGNATURE

Reply With Quote
  #11  
Old June 4th, 2006, 01:50 PM
Lew Pitcher
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Followup: How to Determine my Internet IP Address

PGP SIGNED MESSAGE
Hash: SHA1

Lew Pitcher wrote:
Dave Farrance wrote:
I'm looking for a reasonably future-proof way to find the IP address of
a machine as seen from the Internet.
>

FWIW, I put together some automation, and used the 'free' personal webpage
provided by my ISP to give myself a 'rendesvous' site and redirect webpage.
[snip]

I just realized that the technique I used in the article is probably overkill
for your problem. You can take a look at a simpler procedure that I wrote
about for The Slack World, issue 4 at


HTH
- --
Lew Pitcher

Master Codewright & JAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
PGP SIGNATURE
Version: GnuPG v1.4.2.2 (GNU/Linux)


PVUgG59VxAfrIZYMnT70870=
=+2gx
PGP SIGNATURE

Reply With Quote
  #12  
Old June 4th, 2006, 01:50 PM
Chris F.A. Johnson
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

2006-06-04, Dave Farrance wrote:
I'm looking for a reasonably future-proof way to find the IP address of
a machine as seen from the Internet.
>

This worked once but not now. It was probably removed due to excessive
traffic:
>

wget 2>/dev/null

It's still working.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
My code in this post, if any, assumes the PSIX locale
and is released under the GNU General Public Licence

Reply With Quote
  #13  
Old June 4th, 2006, 01:50 PM
IcessLinux
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Followup: How to Determine my Internet IP Address

Lew Pitcher wrote:
Slackware - Because I know what I'm doing.

yes. None of that point & click nosense!


Reply With Quote
  #14  
Old June 4th, 2006, 03:10 PM
Dave Farrance
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Followup: How to Determine my Internet IP Address

Lew Pitcher <lpitcher@sympatico.cawrote:

>I just realized that the technique I used in the article is probably overkill
>for your problem. You can take a look at a simpler procedure that I wrote
>about for The Slack World, issue 4 at
>


Thanks, but since PCs often negotiate an IP with a local router, which
is even common for home PCs now that wireless networks are popular, it
won't always give your IP address as seen by the Internet.

If, however, you *do* want to find a PC's local leased address, rather
than a fixed IP address that's been assigned to a given interface which
you'd know anyway, then with the latest linux distros (for example), it
would have been assigned by dhclient. So you can find it with this:

#!/bin/bash
myip=`cat /var/lib/dhcp/dhclient*leases | grep -m 1 "address"`
myip=${myip#*address}
myip=${myip%\;}
echo $myip

--
Dave Farrance

Reply With Quote
  #15  
Old June 4th, 2006, 03:10 PM
Dave Farrance
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

"Chris F.A. Johnson" <cfajohnson@gmail.comwrote:

2006-06-04, Dave Farrance wrote:
>This worked once but not now. It was probably removed due to excessive
>traffic:
>>

>wget 2>/dev/null
>

It's still working.

Ah. It is *now*. It wasn't earlier today.

--
Dave Farrance

Reply With Quote
  #16  
Old June 4th, 2006, 03:50 PM
Tim Heaney
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

"Chris F.A. Johnson" <cfajohnson@gmail.comwrites:
>>

>wget 2>/dev/null
>

It's still working.

! That's much nicer. And if we don't happen to have wget, we just
pick our favorite

curl 2>/dev/null

perl -MLWP::Simple -e 'getprint shift'

python -c 'import urllib;print urllib.urlopen("").read(),'

ruby -r uri -r net/http -e 'Net::HTTP.get_print(URI.parse(""))'

tcl -c 'package require http; puts -nonewline [http::data [http::geturl [lindex ""]]]'

lua -e 'h = require("socket.http"); r = h.request(""); io.stdout:write(r)'

And it still does the job in a web browser! Sometimes plain text is
just better.

Tim

Reply With Quote
  #17  
Old June 4th, 2006, 03:50 PM
Barry Margolin
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

In article <@4ax.com>,
Dave Farrance <DaveFarrance@MiTTHiSyahooANDTHiS.co.ukwrote:

I'm looking for a reasonably future-proof way to find the IP address of
a machine as seen from the Internet.

How about setting up an account on dyndns.org, then use nslookup to look
up your hostname. This has the added feature that you can do it from
outside your home network.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
PLEASE post questions in newsgroups, not directly to me
PLEASE don't copy me on replies, I'll read them in the group

Reply With Quote
  #18  
Old June 4th, 2006, 06:30 PM
ed
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

Sun, 04 Jun 2006 10:57:16 GMT
Dave Farrance <DaveFarrance@MiTTHiSyahooANDTHiS.co.ukwrote:

I'm looking for a reasonably future-proof way to find the IP address
of a machine as seen from the Internet.
>

This worked once but not now. It was probably removed due to excessive
traffic:
>

wget 2>/dev/null
>

suggestions please?
>

Has any organisation decided to save the world and provide a
script-parseable IP address of the requesting machine?

www.s5h.net/ip.php

But the inetnet being the way it is means your web-facing IP address is
subject to what ever the middle routers want to do. NAT pool you
perhaps, as the case is with some ISPs, such as AL, or proxy you
maybe, all sorts could happen, it's a large network after all.

--
Regards, Ed :: http://www.usenix.org.uk
just another java hacker
Say N to LNGHRN/VISTA -- google this: "how microsoft is selling
out the public to please hollywood"

Reply With Quote
  #19  
Old June 4th, 2006, 06:30 PM
Andrew Smallshaw
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

2006-06-04, Dave Farrance <DaveFarrance@MiTTHiSyahooANDTHiS.co.ukwrote:
I'm looking for a reasonably future-proof way to find the IP address of
a machine as seen from the Internet.

Just a couple of points to bear in mind that other posters haven't brought up:
Firstly, how many IP addresses does a machine have? ? More? If so does
it matter which is chosen? Indeed, if you're behind NAT you could argue you
don't have ANY. What to do in these cases will by and large depend on what
you're doing with the address once you've got it.

Secondly, future proofing, which you state is important, may be difficult
when the transition is made to IPv6. While the transition seems to have been
permanently a couple of years away for at least the last decade, it seems
resonable to assume that IPv6 will be commonplace in maybe 5 years and
ubiquitous in maybe 10. While creating a script now that can supply either
is likely to be painful, at least make sure the surrounding application can
handle IPv6-style addresses if future-proofing is really important to you.

--
Andrew Smallshaw
andrews@sdf.lonestar.org

Reply With Quote
  #20  
Old June 5th, 2006, 08:30 AM
Marcin Dobrucki
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

Chris F.A. Johnson wrote:

>>This worked once but not now. It was probably removed due to excessive
>>traffic:
>>
>>wget 2>/dev/null

>
>

It's still working.

And will resolv to whatever proxy/gateway you must go through to get
to the web.

/m

Reply With Quote
  #21  
Old June 5th, 2006, 08:30 AM
Dave Farrance
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

ed <ed@noreply.comwrote:

>www.s5h.net/ip.php


Good. Another one that works with the PERL script.

perl -MLWP::Simple -le '$_=get q(http://www.s5h.net/ip.php); \
print $1 if /remote IP is: ((\d{1,3}\.){3}\d{1,3})/'

>But the inetnet being the way it is means your web-facing IP address is
>subject to what ever the middle routers want to do. NAT pool you
>perhaps, as the case is with some ISPs, such as AL, or proxy you
>maybe, all sorts could happen, it's a large network after all.


Yes. If you're connected via a NAT pool or a proxy, this query might be
useful to inform you of that fact. The query can be more useful if the
routers that hide your private IP have NAT tables set up to route some
inward traffic.

--
Dave Farrance

Reply With Quote
  #22  
Old June 5th, 2006, 02:50 PM
Chris F.A. Johnson
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

2006-06-05, Marcin Dobrucki wrote:
Chris F.A. Johnson wrote:
>

This worked once but not now. It was probably removed due to excessive
traffic:

wget 2>/dev/null
>>
>>

>It's still working.
>

And will resolv to whatever proxy/gateway you must go through to get
to the web.

Which is its _raison_d'etre_.

I use it in a script to find either the local address or the
address presented to the web:

if [ "$1" = "-n" ]
then
ip=$(lynx -dump )
else
if=$1
system=$(uname)
case $system in
FreeBSD) sep="inet " ;;
Linux) sep="addr:" ;;
esac
temp=$(ifconfig $if)
temp=${temp#*"$sep"}
ip=${temp%% *}
fi

printf "%s\n" "$ip"


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
My code in this post, if any, assumes the PSIX locale
and is released under the GNU General Public Licence

Reply With Quote
  #23  
Old June 5th, 2006, 06:10 PM
Andrew Gideon
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

Sun, 04 Jun 2006 21:27:43 +0000, ed wrote:

But the inetnet being the way it is means your web-facing IP address is
subject to what ever the middle routers want to do. NAT pool you perhaps,
as the case is with some ISPs, such as AL, or proxy you maybe, all sorts
could happen, it's a large network after all.

It is also possible that you'll be using a different NAT pool and/or proxy
server at different times, or when sending packets to different parts of
the Internet. That is, even if your machine itself has but one static IP
this is no guarantee that the Internet sees your machine that way.

- Andrew


Reply With Quote
  #24  
Old June 5th, 2006, 06:10 PM
Kenan Kalajdzic
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

In comp.unix.shell Dave Farrance <DaveFarrance@omitthisyahooandthis.co.ukwrote:
I'm looking for a reasonably future-proof way to find the IP address of
a machine as seen from the Internet.
>

This worked once but not now. It was probably removed due to excessive
traffic:
>

wget 2>/dev/null
>

suggestions please?

Try using 'ping' with the IP record route option:

ping -c 1 -R www.internic.net

then simply parse the output and extract the IP address of your router's
external interface. Note, however, that this method may not prove more
reliable than using HTTP. It can at least serve as an alternative.

--
Kenan Kalajdzic

Reply With Quote
  #25  
Old June 6th, 2006, 07:30 AM
Dave Farrance
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

Kenan Kalajdzic <kenan@cced.bawrote:

>Try using 'ping' with the IP record route option:
>

ping -c 1 -R www.internic.net
>
>then simply parse the output and extract the IP address of your router's
>external interface. Note, however, that this method may not prove more
>reliable than using HTTP. It can at least serve as an alternative.


Its position in the list depends on the number of routers (if any).
Displaying the whole list can be useful, but I don't see a way to
reliably extract the Internet-facing IP with a script.

--
Dave Farrance

Reply With Quote
  #26  
Old June 6th, 2006, 07:30 AM
Kenan Kalajdzic
Guest
Dev Archives Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
How to Determine my Internet IP Address

Dave Farrance <DaveFarrance@omitthisyahooandthis.co.ukwrote:
Kenan Kalajdzic <kenan@cced.bawrote:
>
>>Try using 'ping' with the IP record route option:
>>

>ping -c 1 -R www.internic.net
>>
>>then simply parse the output and extract the IP address of your router's
>>external interface. Note, however, that this method may not prove more
>>reliable than using HTTP. It can at least serve as an alternative.

>

Its position in the list depends on the number of routers (if any).
Displaying the whole list can be useful, but I don't see a way to
reliably extract the Internet-facing IP with a script.

You are right, it could be a challenge. However, in most cases you can
assume that the first public (routable) address in the list is the one
that is seen from the Internet.

--
Kenan Kalajdzic

Reply With Quote
Reply

Viewing: Web Development Archives FAQs Unix/Linux > How to Determine my Internet IP Address


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
Stay green...Green IT