Results 1 to 4 of 4

Thread: Parsing a cmd command

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    18

    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!

  2. #2
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    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?
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    18

    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

  4. #4
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    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:
    1. ' Computer name
    2.         MsgBox(Environment.MachineName)
    3.  
    4.         ' Username & domain
    5.         MsgBox(My.User.Name)
    6.  
    7.         ' IP address
    8.         Dim myIp() As Net.IPAddress = System.Net.Dns.GetHostAddresses(String.Empty)
    9.         If myIp.Count > 0 Then
    10.             For Each ip As Net.IPAddress In myIp
    11.                 MsgBox(ip.ToString)
    12.             Next
    13.         End If

    On a positive note, your code isn't bad at all. It's small and efficient. Go with what works best.
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width