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
|