Jump to content

[SOLVED] get MAC address (W7:yes/wXP:no)


Wombat
 Share

Recommended Posts

The code works on windows 7 but not on XP... why so? :huh:

#include <File.au3>

Global $sIP, $MAs

$Station=InputBox("Workstation", "enter the workstation", "")

_GetMACFromIP($sIP)
Local $text = StringReplace($MAs, "-", "")
IniWrite(@ScriptDir & "\MAC.ini", "mac_addresses", $Station, $text)


Func _GetMACFromIP($sIP)
    Local $MAC,$MACSize
    Local $MAi,$MAr

;Create the struct
$MAC        = DllStructCreate("byte[6]")

;Create a pointer to an int
$MACSize    = DllStructCreate("int")

;*MACSize = 6;
DllStructSetData($MACSize,1,6)

;call inet_addr($sIP)
$MAr = DllCall ("Ws2_32.dll", "int", "inet_addr", _
                "str", $sIP)
$iIP = $MAr[0]

;Make the DllCall
$MAr = DllCall ("iphlpapi.dll", "int", "SendARP", _
                "int", $iIP, _
                "int", 0, _
                "ptr", DllStructGetPtr($MAC), _
                "ptr", DllStructGetPtr($MACSize))

;Format the MAC address into user readble format: 00:00:00:00:00:00
$MAs    = ""
For $MAi = 0 To 5
    If $MAi Then $MAs = $MAs & "-"
        $MAs = $MAs & Hex(DllStructGetData($MAC,1,$MAi+1),2)
Next

;Return the user readble MAC address
    Return $MAs
EndFunc

Resolved by using this code instead:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=MAG.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <WinAPI.au3>
#include <File.au3>


$IPDetails=_IPDetails()
$Station=InputBox("Workstation", "enter the workstation", "")
Local $text = StringReplace($IPDetails[1], ":", "")
IniWrite(@ScriptDir & "\MAC.ini", "mac_addresses", $Station, $text)

Func _IPDetails()
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True", "WQL", 0x30), $aReturn[5] = [4]
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            If $oObjectItem.IPAddress(0) == @IPAddress1 Then
                $aReturn[1] = $oObjectItem.MACAddress
                $aReturn[2] = $oObjectItem.DefaultIPGateway(0)
            EndIf
        Next
        Return $aReturn
    EndIf
    Return SetError(1, 0, $aReturn)
EndFunc   ;==>_IPDetails
Edited by Wombat

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

anyway.... if you want to use first script

change

$Station=InputBox("Workstation", "enter the workstation", "")

with

$sIP=InputBox("Workstation", "enter the workstation", "")

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • 10 months later...

 

The code works on windows 7 but not on XP... why so? :huh:

#include <File.au3>

Global $sIP, $MAs

$Station=InputBox("Workstation", "enter the workstation", "")

_GetMACFromIP($sIP)
Local $text = StringReplace($MAs, "-", "")
IniWrite(@ScriptDir & "\MAC.ini", "mac_addresses", $Station, $text)


Func _GetMACFromIP($sIP)
    Local $MAC,$MACSize
    Local $MAi,$MAr

;Create the struct
$MAC        = DllStructCreate("byte[6]")

;Create a pointer to an int
$MACSize    = DllStructCreate("int")

;*MACSize = 6;
DllStructSetData($MACSize,1,6)

;call inet_addr($sIP)
$MAr = DllCall ("Ws2_32.dll", "int", "inet_addr", _
                "str", $sIP)
$iIP = $MAr[0]

;Make the DllCall
$MAr = DllCall ("iphlpapi.dll", "int", "SendARP", _
                "int", $iIP, _
                "int", 0, _
                "ptr", DllStructGetPtr($MAC), _
                "ptr", DllStructGetPtr($MACSize))

;Format the MAC address into user readble format: 00:00:00:00:00:00
$MAs    = ""
For $MAi = 0 To 5
    If $MAi Then $MAs = $MAs & "-"
        $MAs = $MAs & Hex(DllStructGetData($MAC,1,$MAi+1),2)
Next

;Return the user readble MAC address
    Return $MAs
EndFunc

Resolved by using this code instead:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=MAG.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <WinAPI.au3>
#include <File.au3>


$IPDetails=_IPDetails()
$Station=InputBox("Workstation", "enter the workstation", "")
Local $text = StringReplace($IPDetails[1], ":", "")
IniWrite(@ScriptDir & "\MAC.ini", "mac_addresses", $Station, $text)

Func _IPDetails()
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True", "WQL", 0x30), $aReturn[5] = [4]
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            If $oObjectItem.IPAddress(0) == @IPAddress1 Then
                $aReturn[1] = $oObjectItem.MACAddress
                $aReturn[2] = $oObjectItem.DefaultIPGateway(0)
            EndIf
        Next
        Return $aReturn
    EndIf
    Return SetError(1, 0, $aReturn)
EndFunc   ;==>_IPDetails

 

None of these scripts work on windows 8, any suggestion?

Thanks!

Link to comment
Share on other sites

What is the error you are receiving or are you getting nothing in the mac.ini?

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Where in your script are you trying the IP address or computer name? Which one of the 2 scripts you quoted are you using?

Please post your script if you've changed either of those.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...