Jump to content
Sign in to follow this  
Wombat

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

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...

Share this post


Link to post
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", "")

 


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

Share this post


Link to post
Share on other sites

 

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!

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

The only time I get the mac address is using "localhost" as the machine name. If I use and IP or other computer name it returns nothing.

No errors though.

Edited by kudrow

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By nacerbaaziz
      hello autoit team
      please i need your help
      i found that the youtube provide a way to get any video informations with this link
      https://youtube.com/get_video_info?video_id=id
      but it incoded i can not read it
      can any one tell me how to decode that please?
    • By Jahar
      Hi,
      I am new to Autoit, Kindly guide me. I wanted to send a message with HTTP/GET to the URL https://ghsff.it/. How to do so?
    • By HenryJiu
      Hello!
      I have a question , about Mac and Autoit3.
      I want to convert my script to Mac App,but Aut2Exe just convert to EXE!
      So I asked if there was a way to convert scripts to MAC App
      My English isn't very good,so don't laugh please😃
    • By nacerbaaziz
      hello sirs, please i created a tool witch get the focused control in a window and play a audio file linked with this controls
      e.g buttons, checkBoxes, radios, comboboxes, and others
      i know that their is a function that give us the control focus but it return the classNN
      i want to get the class name to use it with a switch and
      because their are more than class e.g button tbutton timagebutton tnewButton...
      please can any one help me to get the class name not the classnn
      thanks in advance
×
×
  • Create New...