网卡序列号如何获得?
请各位高手领教!我已经找遍了。[ 本帖最后由 wzhualian888 于 2008-10-6 21:42 编辑 ] MAC:
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
$hGUI = GUICreate("MAC 地址扫描器", 424, 320, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU), $WS_EX_CONTEXTHELP)
GUICtrlCreateGroup("扫描 MAC 地址", 7, 6, 410, 290)
GUICtrlCreateLabel("从", 21, 26, 16, 18, $SS_LEFT + $SS_CENTERIMAGE)
$IPAdd0 = _GUICtrlIpAddress_Create($hGui, 36, 26, 110, 18)
_GUICtrlIpAddress_Set($IPAdd0, @IPAddress1)
GUICtrlCreateLabel("到", 153, 26, 16, 18, $SS_LEFT + $SS_CENTERIMAGE)
$IPAdd1 = _GUICtrlIpAddress_Create($hGui, 174, 26, 110, 18)
_GUICtrlIpAddress_Set($IPAdd1, @IPAddress1)
$Button = GUICtrlCreateCheckbox("扫描(&C)", 293, 25, 55, 20, $BS_PUSHLIKE)
$Save = GUICtrlCreateButton("保存(&S)", 350, 25, 55, 20)
$hListView = _GUICtrlListView_Create($hGUI, "MAC 地址|计算机名|IP地址", 21, 54, 382, 230, -1, 0x00000220)
;$hListView = GUICtrlCreateListView("MAC 地址|计算机名|IP地址", 21, 54, 382, 230)
_GUICtrlListView_SetExtendedListViewStyle ($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES))
;$hImage = _GUIImageList_Create ()
;_GUICtrlListView_SetImageList ($hListView, $hImage, 1)
_GUICtrlListView_SetColumnWidth($hListView, 0, 140)
_GUICtrlListView_SetColumnWidth($hListView, 1, 100)
_GUICtrlListView_SetColumnWidth($hListView, 2, 122)
$hProgress = GUICtrlCreateProgress(7, 300, 410, 18)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
$aIP0 = _GUICtrlIpAddress_GetArray($IPAdd0)
$aIP1 = _GUICtrlIpAddress_GetArray($IPAdd1)
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Save
$List_n=_GUICtrlListView_GetItemCount($hListView)
If Not $List_n Then
MsgBox(16,"错误","请先扫描好之后再点击列表格保存!!!")
Else
IniWrite("config.ini", "Copyright", "Production","www.autoitx.com")
IniWrite("config.ini", "Copyright", "ScanMac last time", _
StringFormat("%4d-%1d-%1d %1d:%02d:%02d", @YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC))
For $i = 0 To $List_n - 1
$MacItem = _GUICtrlListView_GetItemTextArray($hListView, $i)
If $MacItem <> 3 Then ContinueLoop
IniWrite("config.ini", "Mac2Ip", $MacItem, $MacItem & "|" & $MacItem)
Next
MsgBox(64, "提示", "保存列表完成!")
EndIf
Case $Button
Switch GUICtrlRead($Button)
Case 1
_GUICtrlListView_DeleteAllItems($hListView)
TCPStartup()
;定义:步进、IP总数
Local $iStep = 1, $gross, $n = 0
$gross = $aIP0 - $aIP1
If $gross > 0 Then
$iStep = -1
Else
$gross = Abs($gross)
EndIf
$gross += 1
$aIP0 -= $iStep
Do
$aIP0 += $iStep
;_GUICtrlIpAddress_SetArray($IPAdd0, $aIP0)
GUICtrlSetData($hProgress, Int(100 * ($gross - Abs($aIP1 - $aIP0)) / $gross));进度条百分点
$nIP = $aIP0 & "." & $aIP0 & "." & $aIP0 & "." & $aIP0
Ping($nIP, 5)
If @error Then ContinueLoop
$nHost = __TCPIpToName($nIP)
$nMAC = _API_Get_NetworkAdapterMAC($nIP)
If@error Or Not $nHost Then ContinueLoop
;GUICtrlCreateListViewItem($nMAC & "|" & $nHost & "|" & $nIP, $hListView)
_GUICtrlListView_AddItem ($hListView, $nMAC, $n)
_GUICtrlListView_AddSubItem ($hListView, $n, $nHost, 1, 1)
_GUICtrlListView_AddSubItem ($hListView, $n, $nIP, 2, 2)
$n += 1
Until GUICtrlRead($Button) <> 1 Or $aIP0 = $aIP1
TCPStartup()
GUICtrlSetState($Button, 4)
GUICtrlSetData($hProgress, 0)
Case Else
GUICtrlSetData($hProgress, 0)
EndSwitch
Case Else
For $i = 0 To 2
If $aIP1[$i] >= $aIP0[$i] Then ContinueLoop
$aIP1[$i] = $aIP0[$i]
_GUICtrlIpAddress_SetArray($IPAdd1, $aIP1)
Next
EndSwitch
WEnd
Func __TCPIpToName($sIp, $iOption = Default, $hDll_Ws2_32 = Default)
Local $vbinIP, $vaDllCall, $vptrHostent, $vHostent, $sHostnames, $vh_aliases, $i
Local $INADDR_NONE = 0xffffffff, $AF_INET = 2, $sSeperator = @CR
If $iOption = Default Then $iOption = 0
If $hDll_Ws2_32 = Default Then $hDll_Ws2_32 = "Ws2_32.dll"
$vaDllCall = DllCall($hDll_Ws2_32, "long", "inet_addr", "str", $sIp)
If @error Then Return SetError(1, 0, "") ; inet_addr DllCall Failed
$vbinIP = $vaDllCall
If $vbinIP = $INADDR_NONE Then Return SetError(2, 0, "") ; inet_addr Failed
$vaDllCall = DllCall($hDll_Ws2_32, "ptr", "gethostbyaddr", "long*", $vbinIP, "int", 4, "int", $AF_INET)
If @error Then Return SetError(3, 0, "") ; gethostbyaddr DllCall Failed
$vptrHostent = $vaDllCall
If $vptrHostent = 0 Then
$vaDllCall = DllCall($hDll_Ws2_32, "int", "WSAGetLastError")
If @error Then Return SetError(5, 0, "") ; gethostbyaddr Failed, WSAGetLastError Failed
Return SetError(4, $vaDllCall, "") ; gethostbyaddr Failed, WSAGetLastError = @Extended
EndIf
$vHostent = DllStructCreate("ptr;ptr;short;short;ptr", $vptrHostent)
$sHostnames = __TCPIpToName_szStringRead(DllStructGetData($vHostent, 1))
If @error Then Return SetError(6, 0, $sHostnames) ; strlen/sZStringRead Failed
If $iOption = 1 Then
$sHostnames &= $sSeperator
For $i = 0 To 63 ; up to 64 Aliases
$vh_aliases = DllStructCreate("ptr", DllStructGetData($vHostent, 2) + ($i * 4))
If DllStructGetData($vh_aliases, 1) = 0 Then ExitLoop ; Null Pointer
$sHostnames &= __TCPIpToName_szStringRead(DllStructGetData($vh_aliases, 1))
If @error Then
SetError(7) ; Error reading array
ExitLoop
EndIf
Next
Return StringSplit(StringStripWS($sHostnames, 2), @CR)
Else
Return $sHostnames
EndIf
EndFunc ;==>__TCPIpToName
Func __TCPIpToName_szStringRead($iszPtr, $iLen = -1, $hDll_msvcrt = "msvcrt.dll")
Local $aStrLen, $vszString
If $iszPtr < 1 Then Return "" ; Null Pointer
If $iLen < 0 Then
$aStrLen = DllCall($hDll_msvcrt, "int:cdecl", "strlen", "ptr", $iszPtr)
If @error Then Return SetError(1, 0, "") ; strlen Failed
$iLen = $aStrLen + 1
EndIf
$vszString = DllStructCreate("char[" & $iLen & "]", $iszPtr)
If @error Then Return SetError(2, 0, "")
Return SetError(0, $iLen, DllStructGetData($vszString, 1))
EndFunc ;==>__TCPIpToName_szStringRead
Func _API_Get_NetworkAdapterMAC($sIp)
Local $MAC, $MACSize
Local $i, $s, $r, $iIP
$MAC = DllStructCreate("byte")
$MACSize = DllStructCreate("int")
DllStructSetData($MACSize, 1, 6)
$r = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $sIp)
$iIP = $r
$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
If $s = "00:00:00:00:00:00"Then SetError(1)
Return $s
EndFunc ;==>_API_Get_NetworkAdapterMAC
不错,楼上的回答了.. 我晕找一个mac地址这么复杂 #include <ACN_NET.au3>
MsgBox(0,"网卡MAC地址","网卡MAC地址是 " & _API_Get_NetworkAdapterMAC (@IPAddress1))这个简单吧 (@IPAddress1 这个应该是IP地址吧 这个简单吧
非典男人 发表于 2010-1-29 18:12 http://www.autoitx.com/images/common/back.gif
简单 4# 5# 阶段性盗墓 ipconfig /all | find /i "Physical Address" 狮子好久没出现了.. 狮子好久没出现了.. gapkiller 的头像我很喜欢!不知道是否借来用用!
页:
[1]