Jump to content
CristianoIT

mac adress / Text file

Recommended Posts

CristianoIT

Dear All ,

i need your help to complete my project, i want script to check if if this mac address ( 00:65:v7:p0:3d:90) present in this computer and then the script will proceed the command:

in case true:

IniWrite("C:\Clients.text", "Summary", "Files", "yes")

in case false:

IniWrite("C:\Clients.text", "Summary", "Files", "no")

my idea was to find all the mac address then compare it with this 00:65:v7:p0:3d:90 then one of the above command will proceed, but i didnot succeed to find the right script, because of that i asking your help.

thanks guys.

Share this post


Link to post
Share on other sites
Subz

So do you need help finding the mac address, can you show us your code?

Share this post


Link to post
Share on other sites
FrancescoDiMuro

Good morning @CristianoIT, and welcome to the AutoIt forum :)
I think you're italian, but I have to write in English, in order to let other people understand what we're writing :)

I want to help you, but I need you to help yourself! 
So, I won't give you the code on how to do it, but I want you to understand what to do, and do it :)
So, in AutoIt, there are no macros to take directly the MAC Address of your PC...
But, you could use WMI Object to take the MAC Address of your PC.
Take a look at this little hint :)
Feel free to ask ( and use the Code tag if needed ).

Best Regards.


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

ALWAYS GOOD TO READ:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
careca
Posted (edited)

Did you ever come across "getmac"?

This should send you on your way:

#include <AutoItConstants.au3>
$DSK = Run("getmac", '', '', $STDIN_CHILD + $STDOUT_CHILD)
$begin = TimerInit()
$dif = TimerDiff($begin)
Do
    Sleep(100)
    $Read = StdoutRead($DSK, False, False)
    $Str = StringInStr($Read, 'Physical Address')
    If $dif >= 1000 Then
        MsgBox(64, 'Error', 'Timeout')
        ExitLoop
    EndIf
    $dif = TimerDiff($begin)
Until $Str <> 0
;MsgBox(64, 'Result', $Read)
$ReadTr = StringTrimLeft(StringStripWS($Read, 8), 105)
$Split = StringSplit($ReadTr, '\Device', 1)
;MsgBox(64, 'Count', $Split[0])
For $s = 1 To $Split[0]
    If $s <> $Split[0] Then
    MsgBox(64, '', $Split[$s])
    EndIf
Next

Note that i only got one MAC address (only one network adapter), so i couldn't adapt the code for multiple, but maybe you can.

Edited by careca
  • Like 1

Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
CristianoIT

thanks Francesco & Subs for your quick response, i didn't expect that.
actually i am not a programer so for me it is a little bit difficult to write the code or script, because of that i write you guys here, i am not sure if i am will recieve a help 100% because this is just for programer but it will be so nicce if you help me.

going back to my project i found this code it give all the available mac address because for sure normally it will be more than one:

#include <Array.au3>
$b = _GetMACAddress()
_ArrayDisplay($B)

Func _GetMACAddress()
    local $sText, $iPID
    $iPID = Run(@ComSpec & " /c ipconfig /all", '', @SW_HIDE, 6)
    While 1
        $sText &= StdoutRead($iPID)
        If @error Then ExitLoop
    WEnd
    Return StringRegExp($sText, "(?s)(?i)([\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2})", 3)
EndFunc

this code will give a list in all the available macs in at the computer, but how can i compare this list with my mac adress (00:65:v7:p0:3d:90) then how to make make my next command work in case fals & truth? this is the point that i dont know because i am not a programer.

in case true:

IniWrite("C:\Clients.text", "Summary", "Files", "yes")find_mac.au3

in case false:

IniWrite("C:\Clients.text", "Summary", "Files", "no")

 

i hope you could help me in this.

 

Share this post


Link to post
Share on other sites
Subz

Untested but try the following, you could also do it by looping through the array but using _ArraySearch should suffice,

#include <Array.au3>

Local $sClientFile = EnvGet("SystemDrive") & "\Clients.ini" ;~ Sets the Client Ini Filename to %SystemDrive%\Clients.ini

Local $sMacAddress = "00:65:v7:p0:3d:90" ;~ Search for this MacAddress

;~ Get an Array of all MacAddresses on the system
Local $aMacAddresses = _GetMACAddress()
Local $iSearch = _ArraySearch($aMacAddresses, $sMacAddress) ;~ Search for $sMacAddress above within the MacAddress Array
    If $iSearch = -1 Then
        MsgBox(4096, "Mac Address", "Error: Mac Address : " & $sMacAddress & " was not found.") ;~ Mac Address was not found
        IniWrite($sClientFile, "Summary", "Files", "Yes")
    Else
        MsgBox(4096, "Mac Address", "Success: Mac Addresss : " & $sMacAddress & " was found.") ;~ Mac Address was found
        IniWrite($sClientFile, "Summary", "Files", "No")
    EndIf


Func _GetMACAddress()
    local $sText, $iPID
    $iPID = Run(@ComSpec & " /c ipconfig /all", '', @SW_HIDE, 6)
    While 1
        $sText &= StdoutRead($iPID)
        If @error Then ExitLoop
    WEnd
    Return StringRegExp($sText, "(?s)(?i)([\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2})", 3)
EndFunc

 

Share this post


Link to post
Share on other sites
careca

Only enabled MAC's show, with my code. But have it your way.

 


Spoiler

Paster - Main function is to paste text, but has more functions. (No longer mantained, switched to String Trigger)

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
CristianoIT
32 minutes ago, Subz said:

Untested but try the following, you could also do it by looping through the array but using _ArraySearch should suffice,

#include <Array.au3>

Local $sClientFile = EnvGet("SystemDrive") & "\Clients.ini" ;~ Sets the Client Ini Filename to %SystemDrive%\Clients.ini

Local $sMacAddress = "00:65:v7:p0:3d:90" ;~ Search for this MacAddress

;~ Get an Array of all MacAddresses on the system
Local $aMacAddresses = _GetMACAddress()
Local $iSearch = _ArraySearch($aMacAddresses, $sMacAddress) ;~ Search for $sMacAddress above within the MacAddress Array
    If $iSearch = -1 Then
        MsgBox(4096, "Mac Address", "Error: Mac Address : " & $sMacAddress & " was not found.") ;~ Mac Address was not found
        IniWrite($sClientFile, "Summary", "Files", "Yes")
    Else
        MsgBox(4096, "Mac Address", "Success: Mac Addresss : " & $sMacAddress & " was found.") ;~ Mac Address was found
        IniWrite($sClientFile, "Summary", "Files", "No")
    EndIf


Func _GetMACAddress()
    local $sText, $iPID
    $iPID = Run(@ComSpec & " /c ipconfig /all", '', @SW_HIDE, 6)
    While 1
        $sText &= StdoutRead($iPID)
        If @error Then ExitLoop
    WEnd
    Return StringRegExp($sText, "(?s)(?i)([\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2})", 3)
EndFunc

 

thaaaaanks a lot!

it works perfectly but i have to write my mack address like this :(00-50-B6-80-3D-6A )

i test it on win 10

Share this post


Link to post
Share on other sites
Earthshine
Posted (edited)

edit. sorry, coffee (c) not kicked in when I posted this backward post. :P

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Subz
Posted (edited)

Sorry not very good with regular expression, you could just use something like below, and just change the text within the replace field:

Local $sMacAddress = StringReplace("00:65:v7:p0:3d:90", ":", "-")

Alternatively if you wanted to use this as a tool you could use the following code, which will allow you to enter the mac addresses from the command line i.e.

Compile the script as MacAddress.exe

You can now use:

MacAddress.exe 00:65:v7:p0:3d:90

Or

MacAddress.exe 00-65-v7-p0-3d-90

#include <Array.au3>

Local $sMacAddress = StringReplace("00:65:v7:p0:3d:90", ":", "-") ;~ Search for this MacAddress

If $CmdLine[0] Then $sMacAddress = $CmdLine[1]

Local $sClientFile = EnvGet("SystemDrive") & "\Clients.ini" ;~ Sets the Client Ini Filename to %SystemDrive%\Clients.ini

;~ Get an Array of all MacAddresses on the system
Local $aMacAddresses = _GetMACAddress()

Local $iSearch = _ArraySearch($aMacAddresses, $sMacAddress) ;~ Search for $sMacAddress above within the MacAddress Array
    If $iSearch = -1 Then
        MsgBox(4096, "Mac Address", "Error: Mac Address : " & $sMacAddress & " was not found.") ;~ Mac Address was not found
        IniWrite($sClientFile, "Summary", "Files", "Yes")
    Else
        MsgBox(4096, "Mac Address", "Success: Mac Addresss : " & $sMacAddress & " was found.") ;~ Mac Address was found
        IniWrite($sClientFile, "Summary", "Files", "No")
    EndIf

Func _GetMACAddress()
    local $sText, $iPID
    $iPID = Run(@ComSpec & " /c ipconfig /all", '', @SW_HIDE, 6)
    While 1
        $sText &= StdoutRead($iPID)
        If @error Then ExitLoop
    WEnd
    Return StringRegExp($sText, "(?s)(?i)([\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2})", 3)
EndFunc

 

Edited by Subz
Sorry forgot to change StringRegExp

Share this post


Link to post
Share on other sites
CristianoIT
21 minutes ago, Subz said:

Sorry not very good with regular expression, you could just use something like below, and just change the text within the replace field:

Local $sMacAddress = StringReplace("00:65:v7:p0:3d:90", ":", "-")

Alternatively if you wanted to use this as a tool you could use the following code, which will allow you to enter the mac addresses from the command line i.e.

Compile the script as MacAddress.exe

You can now use:

MacAddress.exe 00:65:v7:p0:3d:90

Or

MacAddress.exe 00-65-v7-p0-3d-90

#include <Array.au3>

Local $sMacAddress = StringReplace("00:65:v7:p0:3d:90", ":", "-") ;~ Search for this MacAddress

If $CmdLine[0] Then $sMacAddress = $CmdLine[1]

Local $sClientFile = EnvGet("SystemDrive") & "\Clients.ini" ;~ Sets the Client Ini Filename to %SystemDrive%\Clients.ini

;~ Get an Array of all MacAddresses on the system
Local $aMacAddresses = _GetMACAddress()

Local $iSearch = _ArraySearch($aMacAddresses, $sMacAddress) ;~ Search for $sMacAddress above within the MacAddress Array
    If $iSearch = -1 Then
        MsgBox(4096, "Mac Address", "Error: Mac Address : " & $sMacAddress & " was not found.") ;~ Mac Address was not found
        IniWrite($sClientFile, "Summary", "Files", "Yes")
    Else
        MsgBox(4096, "Mac Address", "Success: Mac Addresss : " & $sMacAddress & " was found.") ;~ Mac Address was found
        IniWrite($sClientFile, "Summary", "Files", "No")
    EndIf

Func _GetMACAddress()
    local $sText, $iPID
    $iPID = Run(@ComSpec & " /c ipconfig /all", '', @SW_HIDE, 6)
    While 1
        $sText &= StdoutRead($iPID)
        If @error Then ExitLoop
    WEnd
    Return StringRegExp($sText, "(?s)(?i)([\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2})", 3)
EndFunc

 

thanks now it works with all symbols.

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

×