473,796 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

finding IP address of computer

How do I find and print to screen the IP address of the computer my
python program is working on?

Apr 27 '06 #1
9 2315
Chris schrieb:
How do I find and print to screen the IP address of the computer my
python program is working on?


IP adresses are bound to network interfaces not to computers.
One Computer can have multiple network interfaces.

--
Servus, Gregor
http://www.gregor-horvath.com
Apr 27 '06 #2
One way:
import socket
socket.getaddri nfo(socket.geth ostname(), None)[0][4][0]


It was the first google hit

Apr 27 '06 #3
hehe, works a charm, cheers mate.

Apr 27 '06 #4
Chris wrote:
hehe, works a charm, cheers mate.


Beware that if you have a different entry in your hosts file you can match a
different name.

Test it:

- add "127.0.0.2 yourhost.yourdo main yourhost" to /etc/hosts
- rerun the code.

You'll see "127.0.0.2" as the result. So take that into account.

--
Jorge Godoy <go***@ieee.org >

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
Apr 27 '06 #5
print '127.0.0.1'

:-P

Apr 27 '06 #6
On 2006-04-27, Gregor Horvath <g.*******@gmx. at> wrote:
Chris schrieb:
How do I find and print to screen the IP address of the computer my
python program is working on?


IP adresses are bound to network interfaces not to computers.
One Computer can have multiple network interfaces.


And each interface can have any number if IP addresses
(including none).

--
Grant Edwards grante Yow! I feel like a wet
at parking meter on Darvon!
visi.com
Apr 27 '06 #7

"Grant Edwards" <gr****@visi.co m> wrote in message
news:12******** *****@corp.supe rnews.com...
On 2006-04-27, Gregor Horvath <g.*******@gmx. at> wrote:
Chris schrieb:
How do I find and print to screen the IP address of the computer my
python program is working on?


IP adresses are bound to network interfaces not to computers.
One Computer can have multiple network interfaces.


And each interface can have any number if IP addresses
(including none).


To answer the OP for typical situations: if you are accessing the internet
via a local network, the network administrator should be able to tell you.
In fact, for some networks, the IP address is part of the interface setup.
If the network is run by a router, it should be able to tell you. If you
are sitting behind a NAT (network address translation) router and you want
to know the external address, there are web pages that echo your externally
visible address back to you.

Terry Jan Reedy

Apr 27 '06 #8
Chris wrote:
How do I find and print to screen the IP address of the computer my
python program is working on?


def readip():
import re, urllib
f = urllib.urlopen( 'http://checkip.dyndns. org')
s = f.read()
m = re.search('([\d]*\.[\d]*\.[\d]*\.[\d]*)', s)
return m.group(0)

myip = readip()
Apr 28 '06 #9
DarkBlue wrote:
Chris wrote:

How do I find and print to screen the IP address of the computer my
python program is working on?

def readip():
import re, urllib
f = urllib.urlopen( 'http://checkip.dyndns. org')
s = f.read()
m = re.search('([\d]*\.[\d]*\.[\d]*\.[\d]*)', s)
return m.group(0)

myip = readip()


IP address and other browser header information available at:

http://xhaus.com/headers
May 1 '06 #10

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

Similar topics

11
2208
by: Picture Dots | last post by:
Ok - I want to check a string for @ in it (Im checking to see if a string that should contain an email holds a @ ) How would I go about this? preg_match? ereg? strstr?Examples? Also - how would I find any non alpha numeric characters in a string so I can give the user an error message. I dont want any characters besides alpha-numeric in the strings.
2
3289
by: FR3AK | last post by:
Hi. does anyone have any idea of how to find the mac address of a remote networking device? I've worked with WMI and it works fine as long as the target machine is a Windows computer, however, i want to return the MAC address of ANY IP device on my network. right now, i have a totally inefficient way to return a mac address, but it's only by dropping to a command prompt and executing the ARP command (all within code....it's not as...
1
18776
by: Uzi Baruch | last post by:
Hi! i want to know if i have an ip address of a computer and its DNS server name, if their is an windows API that can resolve the computer name of the given ip address. or vice verca - given a computer name and it's DNS server, i need to obtain the IP address.
10
1420
by: iwdu15 | last post by:
hi, im making a program that uses the IP address of the computer its on, but i dont kno how to programmaticly find it.....can anyone point me in the rite direction? thanks -- -iwdu15
0
1905
by: NSF12345 | last post by:
Iv developed a small program that looks for a file over our network, and copy it to the location of another computer. Im using the "If FileExists("\\oldpc\main share\Folder\file.txt") Then" way of finding if the file exists, but i want to make it so that it tries to look for the computer, not the file. At the moment this is how i am finding and copying the file: If FileExists("\\oldpc\main share\Folder\file.txt") Then FileCopy "\\oldpc\main...
3
2782
by: Martin Racette | last post by:
Hi, I'm making am app that check which IP is currently use on my network, but I would like to be able to find out the name of the computer to whom the IP belong, and I can not find out how to do it using VB Express 2005 -- Thank You in Advance Merci a l'avance
17
3790
by: abhimanyu.v | last post by:
Hi Guys, I have one doubt. The test program is given below. It uses two way of finding out the offset of a variable in structure. I executed the program and found the same result. My question is what is difference between 1) (unsigned long) &((struct foobar *)0)->foo and
8
4965
by: KDawg44 | last post by:
Hi, I am writing a PHP app for a small business (family member owes me after this...) but they need to get their box back before I am finished. They have a DSL with dynamic ip and I need to be able to SSH in to their box, so I need to write a script that i have run as a cron job that will email me the current public IP of their DSL modem (as it will change). I am not sure the best way to go about this.... I was hoping someone could...
275
12417
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
9685
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
10465
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7558
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
6800
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
5453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
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.