473,805 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Finding IP address of localhost via socket API (or other API)

On Tue, Aug 5, 2008 at 2:50 PM, David York <da********@gma il.comwrote:
Does anybody know how to find the real IP address (e.g.: address visible to
internet) of a machine via Python? In other words I have a machine with an
IP address something like 192.168.1.5, an address given to me by a router.
The router's address (and thus my machine's address) to the outside world is
something realistic, 123.156.123.156 or whatever. How do I get that
number? I've tried socket.getaddri nfo('localhost' , None) but all I get is
127.0.0.1 as expected.

How do I find out my machine's IP address as visible to the outside world?
Thanks a lot.

David
I'm not sure what you are trying to accomplish. The machine I'm typing
this on has a 192.168.x.x number. The router that gave it to me also
has a 192.168.x.x number. However, I know that that is not the IP that
the world sees when my packets finally leave the building.

What if your machine has multiple interface cards in it?

What are you trying to accomplish?
--
Stand Fast,
tjg. [Timothy Grant]
Aug 5 '08 #1
5 2064
Timothy Grant schrieb:
On Tue, Aug 5, 2008 at 2:50 PM, David York <da********@gma il.comwrote:
>Does anybody know how to find the real IP address (e.g.: address visible to
internet) of a machine via Python? In other words I have a machine with an
IP address something like 192.168.1.5, an address given to me by a router.
The router's address (and thus my machine's address) to the outside world is
something realistic, 123.156.123.156 or whatever. How do I get that
number? I've tried socket.getaddri nfo('localhost' , None) but all I get is
127.0.0.1 as expected.
Try scraping a service like http://www.meineip.de/

Diez
Aug 5 '08 #2
Sorry for replying to the replier (Timothy) instead of the OP (David),
but the original post seems to have been eaten by my ISP.

On Tue, 05 Aug 2008 15:48:26 -0700, Timothy Grant wrote:
On Tue, Aug 5, 2008 at 2:50 PM, David York <da********@gma il.comwrote:
>Does anybody know how to find the real IP address (e.g.: address
visible to internet) of a machine via Python? In other words I have a
machine with an IP address something like 192.168.1.5, an address given
to me by a router. The router's address (and thus my machine's address)
to the outside world is something realistic, 123.156.123.156 or
whatever. How do I get that number? I've tried
socket.getaddr info('localhost ', None) but all I get is 127.0.0.1 as
expected.

How do I find out my machine's IP address as visible to the outside
world? Thanks a lot.

David

I'm not sure what you are trying to accomplish. The machine I'm typing
this on has a 192.168.x.x number. The router that gave it to me also has
a 192.168.x.x number. However, I know that that is not the IP that the
world sees when my packets finally leave the building.
That's the IP address the OP probably wants. At least, when I've asked
this exact same question, that's what I meant.

The only way I know of is to query an external server that will tell you.
There's a few of them out there. Here's a few:

http://checkip.dyndns.org/
http://www.showmyip.com
http://www.showmyip.com/simple/
http://whatismyip.org/

The basic algorithm is to connect to one of those sites and fetch the
data it returns, then parse it appropriately. Some of them return a
simple IP address, some a complicated bunch of text, some a nicely
formatted XML document. Some of them only allow you to query the server a
limited number of times. I don't remember which is which.

To get you started, here's an untested piece of code:

import urllib2
import re
data = urllib2.urlopen (site).read()
matcher = re.compile(r"\d {1,3}\.\d{1,3}\ .\d{1,3}\.\d{1, 3}")
ip_address = matcher.search( data).group()

--
Steven
Aug 5 '08 #3
Steven D'Aprano wrote:
The only way I know of is to query an external server that will tell you.
There's a few of them out there. Here's a few:
http://checkip.dyndns.org/
http://www.showmyip.com
http://www.showmyip.com/simple/
http://whatismyip.org/
all four of these show my internal IP of 192.168.x.x in both ie and
firefox. Only http://www.meineip.de/ shows the external IP.

Emile

Aug 5 '08 #4
On Aug 6, 9:51 am, Emile van Sebille <em...@fenx.com wrote:
Steven D'Aprano wrote:
The only way I know of is to query an external server that will tell you.
There's a few of them out there. Here's a few:
http://checkip.dyndns.org/
http://www.showmyip.com
http://www.showmyip.com/simple/
http://whatismyip.org/

all four of these show my internal IP of 192.168.x.x in both ie and
firefox. Onlyhttp://www.meineip.de/shows the external IP.
All four of Steven's list showed my *external* address using Firefox,
as did http://www.meineip.de/
Aug 6 '08 #5
On Tue, Aug 5, 2008 at 4:39 PM, Steven D'Aprano
<st***@remove-this-cybersource.com .auwrote:
Sorry for replying to the replier (Timothy) instead of the OP (David),
but the original post seems to have been eaten by my ISP.

On Tue, 05 Aug 2008 15:48:26 -0700, Timothy Grant wrote:
>On Tue, Aug 5, 2008 at 2:50 PM, David York <da********@gma il.comwrote:
>>Does anybody know how to find the real IP address (e.g.: address
visible to internet) of a machine via Python? In other words I have a
machine with an IP address something like 192.168.1.5, an address given
to me by a router. The router's address (and thus my machine's address)
to the outside world is something realistic, 123.156.123.156 or
whatever. How do I get that number? I've tried
socket.getadd rinfo('localhos t', None) but all I get is 127.0.0.1 as
expected.

How do I find out my machine's IP address as visible to the outside
world? Thanks a lot.

David

I'm not sure what you are trying to accomplish. The machine I'm typing
this on has a 192.168.x.x number. The router that gave it to me also has
a 192.168.x.x number. However, I know that that is not the IP that the
world sees when my packets finally leave the building.

That's the IP address the OP probably wants. At least, when I've asked
this exact same question, that's what I meant.

The only way I know of is to query an external server that will tell you.
There's a few of them out there. Here's a few:

http://checkip.dyndns.org/
http://www.showmyip.com
http://www.showmyip.com/simple/
http://whatismyip.org/

The basic algorithm is to connect to one of those sites and fetch the
data it returns, then parse it appropriately. Some of them return a
simple IP address, some a complicated bunch of text, some a nicely
formatted XML document. Some of them only allow you to query the server a
limited number of times. I don't remember which is which.

To get you started, here's an untested piece of code:

import urllib2
import re
data = urllib2.urlopen (site).read()
matcher = re.compile(r"\d {1,3}\.\d{1,3}\ .\d{1,3}\.\d{1, 3}")
ip_address = matcher.search( data).group()

--
Steven
Now that is a cool solution to the problem. It even works in my work
environment where I have three routers between me and the front door.

--
Stand Fast,
tjg. [Timothy Grant]
Aug 6 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
10909
by: crypto_stonelock | last post by:
Hello, I was wondering if anybody knew how to retrieve the IP address attributed dynamically by your ISP without having to use the info collected on a socket with say .getLocalAddress. I'm using dsl with PPPoE and whenever i try to get the local address, through InetAddress, the network address is returned. So i'm guessing that InetAddress is out.My network is in the way and i don't think i can really go around it. I can't seem to...
1
1201
by: perspolis | last post by:
Hi all How can I find the address that user type in address bar?? I have some subdomains that have a homepage.I want to determine which address is user typed and based on that address load properly information/ thanks in advance
1
2484
by: Ezz | last post by:
I have an interesting problem...and its one of those where I know what I want but don't know how to ask it =) I have an eCommerce application that uses Paypal for its payment gateway. It is an XML webservice that my eComm app makes the request to. Well, It has to do so over a SSL link. Well...I have multiple SSL sites on my Win2003 machine. Each IIS site has its own IP address so I can bind the SSL Cert to each site. Well, the site...
1
3764
by: Phill W. | last post by:
For my sins, I've been given a program to write that uses the Framework Sockets classes. Needless to say, I'm getting problems as I'm going along, but by far my biggest woe is MSDN! Virtually every Socket method says something like ... If you get an Exception, get the ErrorCode property and look it up in the "Windows Sockets Version 2 API error code Documentation". .... but can I find it???
5
2016
by: DaTurk | last post by:
I have this application that has one sender, and multiple receivers, the receivers are subscribing to a multicast group to which the sender is sending information synchronously, while the receivers are receiving asynchronously. My issue, is that if the if the receiver's socket disconnects for any reason I want to be able to detect it and attempt to reconnect. Although I'm uncertain what to look for. I thought the receiver would...
0
201
by: Christian Heimes | last post by:
David York wrote: Most modern routers home routers support the IGD part of UPnP (http://en.wikipedia.org/wiki/Internet_Gateway_Device_Protocol). You can use an UPnP client software to query the router for its WAN IP, connection state and upload / download speed. You may even be able to modify the port forwarding rules with UPnP. I suggest Miniupnpc, because it has nice Python bindungs. Another option is dyndns.org. You can register a...
0
1574
by: =?Utf-8?B?UmFqbmk=?= | last post by:
Dear William Stacey, I have written a server code using the Windows Socket API's. Wherein I have created the socket and bound it to a particular IP address and port number. Later I have made the socket in non-blocking mode by using the proper socket option ( i.e. SO_RCVTIMEO). After which with the use of recv() I am trying to get into the receive mode. Here as the receive time out is being used the socket should come out of the block...
0
1940
Airslash
by: Airslash | last post by:
Hello, not really sure if this will lead to something, but I just want to have a small discussion about the Berkley Sockets API. Recently i've been working on TCP Client/Server architectures, and while these lovely Sockets do the things they're supposed to do, I often find myself struggling with the API or inner workings of the Sockets. An example is when I establish a connection on a local port to a remote port. When the connection is...
0
1281
by: Andreas Englund | last post by:
Hello, I need to communication with an ERP using sockets (API-calls) from a .NET website and I am wondering where to search for information on how to work with connection pooling within IIS. Is there some kind of framework that could be of help to achieve this? A dll-file will be used to make the socket-calls. Any other thoughts on how to do a connection pooling when using sockets? Thanks for any replies / Andreas
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10107
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.