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

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

 

转载于:https://www.cnblogs.com/leme-chen/p/9322560.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值