Malcolm,
Code to get MAC address of the current machine or in fact any machine on the
network

Dave Crozier

######
# Start of Code
#
import ctypes
import socket
import struct

def get_macaddress(host):
    """ Returns the MAC address of a network host, requires >= WIN2K. """
    
    # Check for api availability
    try:
        SendARP = ctypes.windll.Iphlpapi.SendARP
    except:
        raise NotImplementedError('Usage only on Windows 2000 and above')
        
    # Doesn't work with loopbacks, but let's try and help.
    if host == '127.0.0.1' or host.lower() == 'localhost':
        host = socket.gethostname()
    
    # gethostbyname blocks, so use it wisely.
    try:
        inetaddr = ctypes.windll.wsock32.inet_addr(host)
        if inetaddr in (0, -1):
            raise Exception
    except:
        hostip = socket.gethostbyname(host)
        inetaddr = ctypes.windll.wsock32.inet_addr(hostip)
    
    buffer = ctypes.c_buffer(6)
    addlen = ctypes.c_ulong(ctypes.sizeof(buffer))
    if SendARP(inetaddr, 0, ctypes.byref(buffer), ctypes.byref(addlen)) !=
0:
        raise WindowsError('Retreival of mac address(%s) - failed' % host)
    
    # Convert binary data into a string.
    macaddr = ''
    for intval in struct.unpack('BBBBBB', buffer):
        if intval > 15:
            replacestr = '0x'
        else:
            replacestr = 'x'
        macaddr = ''.join([macaddr, hex(intval).replace(replacestr, '')])
    
    return macaddr.upper()

if __name__ == '__main__':
    print 'Your mac address is %s' % get_macaddress('localhost')

#
#End of Code
##########

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Malcolm Greene
Sent: 14 January 2008 10:35
To: profox@leafe.com
Subject: [NF] Python/Dabo OS specific development issues (VFP's
sys()functions)

Ed/Paul,

If one is developing Python/Dabo applications, how do you program for OS
specific issues like:

- screen size and color resolution
- desktop space available for application (single/multi-monitor setups)
- system metrics (default colors, sounds, fonts, etc)
- interface to clipboard
- printer properties and control
- available memory and ability to control max memory usage like
sys(3050)
- pointing device properties and events (mouse wheel events)
- common dialogs (file, folder, color, font, messagebox, etc)
- path related information
- OS event binding
- timer events, system date/time values
- keyboard events
- access to environment variables (SET <var>=<value>)
- network card mac address
- guid generation
- name and path of running executable (and is it already running)
- list of drives and drive properties (size, free space)
- access to command line parameters
- font discovery
- number and type of CPUs
- OS version info
- starting, enumerating/monitoring, and stopping other processes/tasks
- returning application exit codes
- currently logged in user
- system power status (battery info, etc)
- pipes, shared memory, mutexes
- audio, video output
- scanner based input

Thanks!
Malcolm


[excessive quoting removed by server]

_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to