473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Enumerating Network Adapters

Hi all,

I'd like to get, in a portable way, a list of all
network adapters on a local machine running some
python code.

socket.gethostname() does not seem enough, as it
only returns one name ; I'd like to get all
available IPs.

I could process ipconfig or ifconfig outputs, but
this is OS-dependant and not very future-proof...

Best regards,
Olivier Parisy.

Jul 18 '05 #1
7 4109
> I could process ipconfig or ifconfig outputs, but
this is OS-dependant and not very future-proof...


This has been discussed quite a few times on this NG, search google groups.
However IMHO there is no general system built-in way (AFAIK not even posix)
for doing this, you'll end up parsing tool output anyway...

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
Diez B. Roggisch wrote:
This has been discussed quite a few times on this NG, search google groups.
However IMHO there is no general system built-in way (AFAIK not even posix)
for doing this, you'll end up parsing tool output anyway...
I should have done this first, my mistake...

But actually, a previously posted message suggests a portable way to get
the platform IPs. Citing John Abel :
socket.gethostbyaddr( socket.gethostname() ) will return all the
details that you need to know. For example, the output of that
command on my machine is :

('hallows', [], ['101.101.101.102', '10.253.1.118'])


Are there some pitfalls I'm not aware of ?

Thanks,
Olivier Parisy.

Jul 18 '05 #3
Olivier Parisy wrote:
[snip]
But actually, a previously posted message suggests a portable way to get
the platform IPs. Citing John Abel :
> socket.gethostbyaddr( socket.gethostname() ) will return all the
> details that you need to know. For example, the output of that
> command on my machine is :
>
> ('hallows', [], ['101.101.101.102', '10.253.1.118'])


Are there some pitfalls I'm not aware of ?


Doesn't seem to work right on Windows, for me at least:
socket.gethostbyaddr(socket.gethostname())

('<my machine name>', [], ['169.254.0.100'])

It returned the least useful of my 3 IP addresses - my loopback adapter
- but didn't return my LAN and wireless IPs.

-Dave
Jul 18 '05 #4
Dave Brueck <da**@pythonapocrypha.com> writes:
Olivier Parisy wrote:
[snip]
But actually, a previously posted message suggests a portable way to get
the platform IPs. Citing John Abel :
> socket.gethostbyaddr( socket.gethostname() ) will return all the
> details that you need to know. For example, the output of that
> command on my machine is :
>
> ('hallows', [], ['101.101.101.102', '10.253.1.118'])

Are there some pitfalls I'm not aware of ?


Doesn't seem to work right on Windows, for me at least:
>>> socket.gethostbyaddr(socket.gethostname())

('<my machine name>', [], ['169.254.0.100'])

It returned the least useful of my 3 IP addresses - my loopback
adapter - but didn't return my LAN and wireless IPs.


If anyone really needs it, I can post code for windows using ctypes to
collect ip-addresses and netmasks together with the name and description
of all network adapters.

Thomas
Jul 18 '05 #5
> > It returned the least useful of my 3 IP addresses - my loopback
adapter - but didn't return my LAN and wireless IPs.


Interesting! I have Python installed on 10 W2K servers and I'm using
the same construct to get addresses. Works fine for me.
Jul 18 '05 #6
Elbert Lev wrote:
It returned the least useful of my 3 IP addresses - my loopback
adapter - but didn't return my LAN and wireless IPs.

Interesting! I have Python installed on 10 W2K servers and I'm using
the same construct to get addresses. Works fine for me.


WinXP Pro here - I wonder if that's the difference.

-Dave
Jul 18 '05 #7
Dave Brueck wrote:
Elbert Lev wrote:
It returned the least useful of my 3 IP addresses - my loopback
adapter - but didn't return my LAN and wireless IPs.


Interesting! I have Python installed on 10 W2K servers and I'm using
the same construct to get addresses. Works fine for me.

WinXP Pro here - I wonder if that's the difference.


Interestingly, I have the same problem with XP Pro.

But socket.gethostbyname_ex seems to do the trick for me !

Regards,
Olivier.
Jul 18 '05 #8

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

Similar topics

0
by: Gordon Knote | last post by:
Hi how can I enumerate (and get information about) all installed network adapters on a local machine (in .net) Thanks a lo Gordon
3
by: LK | last post by:
Can PLEASE SOMEONE HELP me how to enumerate local network interfaces (i.e ip addresses, dns, etc.) with csharp. I need the type of information that would come up when typing ipconfig /all ...
0
by: Michael C | last post by:
Hi all, After a lot of research, I've come to some realizations about enumerating Named Instances of MSDE. NetServerEnum() Win32 API function doesn't work, SQL-DMO doesn't work, no standard...
3
by: Maniaque | last post by:
Does anybody knows, how can I address multiply network adapters on one computer? I've looked up through classes reference and found nothing. Thanks in advance. -- .... blood, sugar, sex,...
1
by: Glenn Leifheit | last post by:
Does anyone have any sample code on enumerating network shares with vb.net. I here you need to use wither an API or WMI, or are there other recomendations. Thanks Glenn
3
by: Joe User | last post by:
Hi - I found the class below on another website (www.devx.com) and can't seem to figure out how to make a call to this class to retrieve the machines and put them in a listbox. I am definitely a...
1
by: Phil Galey | last post by:
Is there any way of enumerating all printers, including network printers in VB.NET? printing.PrinterSettings.InstalledPrinters only enumerates printers attached to the local workstation. ...
0
by: amir | last post by:
Hello All, I am currently looking for writing an application that will act like a network bridge. Meaning, I have 2 network adapters and i want all thing from 1 adapter will pass directly to the...
4
by: =?Utf-8?B?TWFydGlu?= | last post by:
In Device Manager under Network Adapters, nearly all (about 20) items have a yellow warning symbol. The first item, Microsoft 6to4 Adapter says driver is up-to-date BUT says "This device is not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.