Advertisement
calfred2808

GET ALL IPADDRESS IN LAN NETWORK

Sep 6th, 2018
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.64 KB | None | 0 0
  1. Class SurroundingClass
  2.     Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
  3.         Dim netUtility As Process = New Process()
  4.         netUtility.StartInfo.FileName = "net.exe"
  5.         netUtility.StartInfo.CreateNoWindow = True
  6.         netUtility.StartInfo.Arguments = "view"
  7.         netUtility.StartInfo.RedirectStandardOutput = True
  8.         netUtility.StartInfo.UseShellExecute = False
  9.         netUtility.StartInfo.RedirectStandardError = True
  10.         netUtility.Start()
  11.         Dim streamReader As StreamReader = New StreamReader(netUtility.StandardOutput.BaseStream, netUtility.StandardOutput.CurrentEncoding)
  12.         Dim line As String = ""
  13.  
  14.         While (CSharpImpl.__Assign(line, streamReader.ReadLine())) IsNot Nothing
  15.  
  16.             If line.StartsWith("\") Then
  17.                 Dim pcname As String = line.Substring(2).Substring(0, line.Substring(2).IndexOf(" ")).ToUpper()
  18.                 Dim myIP As String = Convert.ToString(Dns.GetHostByName(line.Substring(2).Substring(0, line.Substring(2).IndexOf(" ")).ToUpper()).AddressList(0).ToString())
  19.                 Dim item As ListViewItem = New ListViewItem(New String() {pcname, myIP}, 0)
  20.                 listView1.Items.AddRange(New ListViewItem() {item})
  21.             End If
  22.         End While
  23.  
  24.         streamReader.Close()
  25.         netUtility.WaitForExit(1000)
  26.     End Sub
  27.  
  28.     Private Class CSharpImpl
  29.         <Obsolete("Please refactor calling code to use normal Visual Basic assignment")>
  30.         Shared Function __Assign(Of T)(ByRef target As T, value As T) As T
  31.             target = value
  32.             Return value
  33.         End Function
  34.     End Class
  35. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement