'窗体上加入控件command1,然后复制下面代码,运行,按command1即可。
Option Explicit
Private Declare Function OpenProcess Lib "kernel32" (ByVal _
dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) _
As Long
Private Const INFINITE = -1&
Private Const SYNCHRONIZE = &H100000
Private Sub Command1_Click()
Dim i As Long, S As String, FileName As String, Ip As String, Mac As String
Dim TaskID As Long ' Task-ID des DOS-Fensters
Dim ProcID As Long ' Prozess-ID des DOS-Fensters
FileName = "c:/1.txt"
If Dir(FileName) <> "" Then Kill FileName
TaskID = Shell("cmd.exe /c arp -a>>c:/1.txt", vbHide)
DoEvents
ProcID = OpenProcess(SYNCHRONIZE, False, TaskID)
Call WaitForSingleObject(ProcID, INFINITE)
Open FileName For Input As #1
S = StrConv(InputB(LOF(1), 1), vbUnicode)
Close #1
i = InStr(1, S, "type" & vbNewLine, vbTextCompare)
S = Trim(Mid(S, i + 6))
i = InStr(S, " ")
Ip = Left(S, i - 1)
S = LTrim(Mid(S, i))
i = InStr(S, " ")
Mac = Left(S, i - 1)
MsgBox "IP:" & Ip & vbNewLine & "MAC:" & Mac, vbInformation, "网关参数"
End Sub
获取网关IP和MAC 的VB源码
最新推荐文章于 2023-04-06 23:14:17 发布