1. 程式人生 > >vb.net 使用ip查詢(Host Name)(WorkGroup Name)(MAC Address)-運用cmd及nbtstat命令

vb.net 使用ip查詢(Host Name)(WorkGroup Name)(MAC Address)-運用cmd及nbtstat命令

cmd命令 nat start line shell 語句 owin app tst

Sub nbtstat(ByVal ip As String)
Dim strRst, strRst1, strRst2, strRst3 As String
Dim n1, n2, n3 As Integer
Try
Dim p As New Process() ‘用Process就可以
p.StartInfo.FileName = "cmd.exe"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardInput = True
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardError = True
p.StartInfo.CreateNoWindow = True
p.Start()
Application.DoEvents()
p.StandardInput.WriteLine("cmd /c C:\\Windows\\sysnative\\nbtstat.exe -a" & ip) ‘這個就是cmd命令,64位電腦用
p.StandardInput.WriteLine("Exit") ‘這個是退出語句
strRst = p.StandardOutput.ReadToEnd() ‘執行完語句後取得顯示內容.
p.Close()
Catch ex As Exception
End Try
‘之後就是你自己的代碼了...
If InStrRev(strRst, "找不到主機") > 0 Then
strRst1 = "找不到主機"
End If

If Not strRst1 = "找不到主機" Then
n1 = InStrRev(strRst, "0> 唯一") - 22
strRst1 = Mid(strRst, n1, 20)
strRst1 = strRst1.Replace(" ", "") ‘Host Name

n2 = InStrRev(strRst, "0> 組") - 22
strRst2 = Mid(strRst, n2, 20)
strRst2 = strRst2.Replace(" ", "") ‘WorkGroup Name

n3 = InStrRev(strRst, "MAC") + 8
strRst3 = Mid(strRst, n3, 20)
strRst3 = strRst3.Replace(" ", "") ‘MAC Address
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
nbtstat(" 10.0.2.1")
End Sub

vb.net 使用ip查詢(Host Name)(WorkGroup Name)(MAC Address)-運用cmd及nbtstat命令