|
-
Jul 27th, 2011, 02:49 PM
#1
Thread Starter
Junior Member
Parsing a cmd command
I may be getting in way over my head, but here it goes. I am developing a small application for use on a helpdesk. The application will be installed on the client pc's and will be used primarily by the end user to assist the technician on the phone if the user's pc is offline or inaccessible. One part of the application gives the user their IP address, DNS address, DHCP address, and gateway address. I have it to where it will put all of those in the corresponding fields inside a form, but it does not work correctly outside of a domain. Outside of a domain it only gives the IP address. I am sure it is probably how I coded it, but I cannot think of any other way to get that info in a user friendly way. Is there a way to parse a command prompt command to specific fields inside of a form such as the command ipconfig /all? That way it would always give the correct info regardless if they are on a domain or not. If you would like to see my code because it would help you help me, then just let me know. Thanks in advance. You guys rock!
-
Jul 27th, 2011, 03:49 PM
#2
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?
-
Jul 27th, 2011, 03:59 PM
#3
Thread Starter
Junior Member
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
-
Aug 4th, 2011, 12:02 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|