找回密码
 加入
搜索
查看: 2157|回复: 2

[网络通信] MAC地址问题

[复制链接]
发表于 2014-9-23 16:01:36 | 显示全部楼层 |阅读模式
用论坛上的MAC地址获得函数,IP10.120.197.1-10.120.197.192都是错的,10.12.197.193开始才对,为啥的,求高手指教
Func _GetMAC($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   ;==>_GetMAC

Func _StringIsIP($strIP)
$str = StringSplit($strIP, ".")
If $str[0] <> 4 Then
   Return ("")
ElseIf StringIsDigit($str[1]) <> 1 Or StringIsDigit($str[2]) <> 1 Or StringIsDigit($str[3]) <> 1 Or StringIsDigit($str[4]) <> 1 Then
   Return ("")
ElseIf $str[1] > 255 Or $str[2] > 255 Or $str[3] > 255 Or $str[4] > 255 Then
   Return ("")

Else
   $strIP = Int($str[1]) & "." & Int($str[2]) & "." & Int($str[3]) & "." & Int($str[4])
   Return $strIP

EndIf
EndFunc
发表于 2014-9-23 19:58:54 | 显示全部楼层
IP10.120.197.1-10.120.197.192都是错的, 10.12.197.193开始才对

不是一个网段情况下,ARP广播不到的。
 楼主| 发表于 2014-9-24 08:26:11 | 显示全部楼层
谢谢俄,因该是这个问题
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-3 14:11 , Processed in 0.074957 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表