Sign in to follow this  
Followers 0
SandelPerieanu

GetMac with StdOutRead and nbtstat

11 posts in this topic

Func _GetMacAddress($_phisycaladdress)
    Local $chk_1 = StringReplace($_phisycaladdress, '.', '') / 1
    If @extended <> 3 Or $chk_1 < 1 Then Return ''
    Local $chk_2 = StringSplit($_phisycaladdress, '.', 1)
    For $idx_chk = 1 To $chk_2[0]
        If ($chk_2[$idx_chk] / 1) < 0 or ($chk_2[$idx_chk] / 1) > 255 Then Return ''
    Next
    Local $_buf = ''
    Local $_pid = Run('nbtstat -a ' & $_phisycaladdress, '', @SW_HIDE, 2)
    Do
        $_buf &= StdoutRead($_pid)
    Until @error
    If StringReplace($_buf, 'MAC Address = ', '') <> $_buf Then
        $chk_3 = StringSplit($_buf, 'MAC Address = ', 1)
        Return StringReplace(StringReplace($chk_3[2], @CR, ''), @LF, '')
    EndIf
    Return ''
EndFunc   ;==>_GetMacAddress

MsgBox(0, '', _GetMacAddress('192.168.0.1'))

Share this post


Link to post
Share on other sites



Moved to Scripts & Scraps where it belongs.

Share this post


Link to post
Share on other sites

Why is there no description of your function? What does it do?

Share this post


Link to post
Share on other sites

It seems to be something like this:

Func _GetMACFromIP($sIP)
    Local $MAC, $MACSize
    Local $i, $s, $r, $iIP
    $MAC = DllStructCreate("byte[6]")
    $MACSize = DllStructCreate("int")
    DllStructSetData($MACSize, 1, 6)
    $r = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $sIP)
    $iIP = $r[0]
    $r = DllCall("iphlpapi.dll", "int", "SendARP", "int", $iIP, "int", 0, "ptr", DllStructGetPtr($MAC), "ptr", DllStructGetPtr($MACSize))
    $s = ""
    For $i = 0 To 5
        If $i Then $s = $s & ":"
        $s = $s & Hex(DllStructGetData($MAC, 1, $i + 1), 2)
    Next
    Return $s
EndFunc   ;==>_GetMACFromIPoÝ÷ Ù8b²­²Ø^0uÚÞ²ÊjrI©©æ®¶­sdgVæ2ôvWDÔ4g&öÔb33c·4 Æö6Âb33c´Ô2Âb33c´Ô56¦P Æö6Âb33c¶Âb33c·2Âb33c·"Âb33c¶ b33c´Ô2ÒFÆÅ7G'V7D7&VFRgV÷C¶'FU³eÒgV÷C² b33c´Ô56¦RÒFÆÅ7G'V7D7&VFRgV÷C¶çBgV÷C² FÆÅ7G'V7E6WDFFb33c´Ô56¦RÂÂb b33c·"ÒFÆÄ6ÆÂgV÷Cµw3%ó3"æFÆÂgV÷C²ÂgV÷C¶çBgV÷C²ÂgV÷C¶æWEöFG"gV÷C²ÂgV÷C·7G"gV÷C²Âb33c·4 b33c¶Òb33c·%³Ð b33c·"ÒFÆÄ6ÆÂgV÷C¶ÇæFÆÂgV÷C²ÂgV÷C¶çBgV÷C²ÂgV÷Cµ6VæD%gV÷C²ÂgV÷C¶çBgV÷C²Âb33c¶ÂgV÷C¶çBgV÷C²ÂÂgV÷C·G"gV÷C²ÂFÆÅ7G'V7DvWEG"b33c´Ô2ÂgV÷C·G"gV÷C²ÂFÆÅ7G'V7DvWEG"b33c´Ô56¦R b33c·2ÒgV÷C²gV÷C° f÷"b33c¶ÒFòP bb33c¶FVâb33c·2Òb33c·2fײgV÷C³¢gV÷C° b33c·2Òb33c·2fײWFÆÅ7G'V7DvWDFFb33c´Ô2ÂÂb33c¶²Â" æW@ &WGW&âb33c·0¤VæDgVæ2³ÓÒfwCµôvWDÔ4g&öÔ ¢b33c´ÒçWD&÷gV÷C²gV÷C²ÂgV÷C´FG&W73¢gV÷C²¢b33c´Ô2ÒôvWDÔ4g&öÔb33c´¤×6t&÷CÂgV÷C²gV÷C²ÂgV÷C´Ô3¢gV÷C²f×´5$Äbfײb33c´Ô2

!! THIS FUNKTION ISN'T WRITTEN BY ME !!


[CENTER]Sorry for my bad English... ;)[/CENTER]

Share this post


Link to post
Share on other sites

It seems to be something like this:

Func _GetMACFromIP($sIP)
    Local $MAC, $MACSize
    Local $i, $s, $r, $iIP
    $MAC = DllStructCreate("byte[6]")
    $MACSize = DllStructCreate("int")
    DllStructSetData($MACSize, 1, 6)
    $r = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $sIP)
    $iIP = $r[0]
    $r = DllCall("iphlpapi.dll", "int", "SendARP", "int", $iIP, "int", 0, "ptr", DllStructGetPtr($MAC), "ptr", DllStructGetPtr($MACSize))
    $s = ""
    For $i = 0 To 5
        If $i Then $s = $s & ":"
        $s = $s & Hex(DllStructGetData($MAC, 1, $i + 1), 2)
    Next
    Return $s
EndFunc   ;==>_GetMACFromIP oÝ÷ Ù8b²­²Ø^0uÚÞ²ÊjrI©©æ®¶­sdgVæ2ôvWDÔ4g&öÔb33c·4¢Æö6Âb33c´Ô2Âb33c´Ô56¦P¢Æö6Âb33c¶Âb33c·2Âb33c·"Âb33c¶¢b33c´Ô2ÒFÆÅ7G'V7D7&VFRgV÷C¶'FU³eÒgV÷C²¢b33c´Ô56¦RÒFÆÅ7G'V7D7&VFRgV÷C¶çBgV÷C²¢FÆÅ7G'V7E6WDFFb33c´Ô56¦RÂÂb¢b33c·"ÒFÆÄ6ÆÂgV÷Cµw3%ó3"æFÆÂgV÷C²ÂgV÷C¶çBgV÷C²ÂgV÷C¶æWEöFG"gV÷C²ÂgV÷C·7G"gV÷C²Âb33c·4¢b33c¶Òb33c·%³Ð¢b33c·"ÒFÆÄ6ÆÂgV÷C¶ÇæFÆÂgV÷C²ÂgV÷C¶çBgV÷C²ÂgV÷Cµ6VæD%gV÷C²ÂgV÷C¶çBgV÷C²Âb33c¶ÂgV÷C¶çBgV÷C²ÂÂgV÷C·G"gV÷C²ÂFÆÅ7G'V7DvWEG"b33c´Ô2ÂgV÷C·G"gV÷C²ÂFÆÅ7G'V7DvWEG"b33c´Ô56¦R¢b33c·2ÒgV÷C²gV÷C°¢f÷"b33c¶ÒFòP¢bb33c¶FVâb33c·2Òb33c·2fײgV÷C³¢gV÷C°¢b33c·2Òb33c·2fײWFÆÅ7G'V7DvWDFFb33c´Ô2ÂÂb33c¶²Â"¢æW@¢&WGW&âb33c·0¤VæDgVæ2³ÓÒfwCµôvWDÔ4g&öÔ ¢b33c´ÒçWD&÷gV÷C²gV÷C²ÂgV÷C´FG&W73¢gV÷C²¢b33c´Ô2ÒôvWDÔ4g&öÔb33c´¤×6t&÷CÂgV÷C²gV÷C²ÂgV÷C´Ô3¢gV÷C²f×´5$Äbfײb33c´Ô2

!! THIS FUNKTION ISN'T WRITTEN BY ME !!

don't work for me this!

result only 00:00:00:00:00:00

Share this post


Link to post
Share on other sites

?¿

It works for me. You have to enter your LAN-IP.


[CENTER]Sorry for my bad English... ;)[/CENTER]

Share this post


Link to post
Share on other sites

don't work for me this!

result only 00:00:00:00:00:00

you can use also @ipadress1

Share this post


Link to post
Share on other sites

@Schlumpf

This is useful to me. Thank you for posting it even if you didn't write it.

Share this post


Link to post
Share on other sites

@Schlumpf

This is useful to me. Thank you for posting it even if you didn't write it.

Same here, good stuff. Thanks to the writer and to Schlumpf for posting it.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

thx !

long time looking for this stuff.

both scripts are working.

the first one by psandu.ro : you have to check $_buf before splitting. on a non-english system the report is different and therefore the extraction of the MAC Address must be adapted.

very nice !

j.

Edit: the second script (_GetMACFromIP) is waaaaaaay faster (about factor 100 !), and you don't need to check the spelling !

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

Thank you very much for that script ;)

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  
Followers 0