Re: Parsing a cmd command
Or you could get the information from the System.Net class or My.Computer class. What code do you have?
Re: Parsing a cmd command
Matt,
Here is the code I have to pull all the ip info. To give you an idea of what the form is like, I have empty labels that I drop the addresses into. If you need anything else, just let me know:
'Display IP address of local machine
Dim ipEntry As IPHostEntry = Dns.GetHostByName(Dns.GetHostName)
Me.lblip.Text = ipEntry.AddressList(0).ToString()
'Display DNS of local machine
Dim myiphost As IPHostEntry = Dns.GetHostEntry(UserDomainName)
Dim myipaddresses() As IPAddress = myiphost.AddressList
Dim myipaddress As IPAddress
For Each myipaddress In myipaddresses
lbldns.Text = myipaddress.ToString
Next
'Display DHCP server address of local machine
Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
Dim adapter As NetworkInterface
For Each adapter In adapters
Dim adapterProperties As IPInterfaceProperties = adapter.GetIPProperties()
Dim addresses As IPAddressCollection = adapterProperties.DhcpServerAddresses
If addresses.Count > 0 Then
MessageBox.Show(adapter.Description)
Dim address As IPAddress
For Each address In addresses
lbldhcp.Text = address.ToString()
Next
End If
Next
'Display Default Gateway of local machine
Dim myNetworkAdapaters() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces
Dim myadapprops As IPInterfaceProperties = Nothing
Dim myGateways As GatewayIPAddressInformationCollection = Nothing
For Each myNetworkAdapter As NetworkInterface In myNetworkAdapaters
myadapprops = myNetworkAdapter.GetIPProperties
myGateways = myadapprops.GatewayAddresses
For Each gateway As GatewayIPAddressInformation In myGateways
lblgateway.Text = gateway.Address.ToString()
Next
Next
End Sub
Re: Parsing a cmd command
Sorry for the late reply. One source of good information here: http://msdn.microsoft.com/en-us/libr...ollection.aspx
Also, I was able to write the following code for you:
vb Code:
' Computer name
MsgBox(Environment.MachineName)
' Username & domain
MsgBox(My.User.Name)
' IP address
Dim myIp() As Net.IPAddress = System.Net.Dns.GetHostAddresses(String.Empty)
If myIp.Count > 0 Then
For Each ip As Net.IPAddress In myIp
MsgBox(ip.ToString)
Next
End If
On a positive note, your code isn't bad at all. It's small and efficient. Go with what works best.