ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: get mac/ physical address of network card with python
by Wolfgang Strobl other posts by this author
Aug 26 2001 10:19PM messages near this date
Re: problem with pythonwin32 | Re: Question about indentation and bugs
On Sun, 26 Aug 2001 11:06:14 -0400, Scott Syms <Scott.Syms@[...].ca> 
wrote :

> Hi, folks-
> 
> Wondering if anyone knew how to grab the mac address of a network card from
> within Python.

Well, the appended programm prints the mac addess for the first adapter
on Windows. I guess you'll have to fiddle it into a python extension
yourself.  Or use it in a pipe like so:
macaddr=os.popen("p1.exe").read()

Or just parse the output of  os.popen("ipconfig /all").read()
for "Physical Address", i.e.

re.search("Physical Address.*:(.{18,18})",os.popen("ipconfig /all").read(),re.M).group(1)


<snip> 

#include "stdafx.h"
#include <stdio.h> 
#include <windows.h> 
#include <IpTypes.h> 
#include <Iphlpapi.h> 

int main(int argc, char* argv[])
{
	IP_ADAPTER_INFO* ai;
	unsigned long lai;
	int i,rc;
	lai=10000;
	ai=(IP_ADAPTER_INFO*)malloc(lai);
	rc=GetAdaptersInfo(ai,&lai);
	if (rc==0)
	for (i=0;i<6;i++)
		printf("%02x ",ai-> Address[i]);
	return 0;

}

-- 
Thank you for observing all safety precautions
-- 
http://mail.python.org/mailman/listinfo/python-list

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved