Results 1 to 5 of 5

Thread: [2008] WMI Network Information (IP Address)

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    [2008] WMI Network Information (IP Address)

    Hello, Still on the WMI problems :-)

    I am trying to get the IP address of each machine using the WMI because I am using WMI for other stuff its just easyier to do it all through that.

    I have the correct command to get IP address information but when it runs it comes up with lots, this is only a sample of what it has brought up on my pc:

    Code:
    -----------------------------------
    Win32_NetworkAdapterConfiguration instance
    -----------------------------------
    IPAddress:
    -----------------------------------
    Win32_NetworkAdapterConfiguration instance
    -----------------------------------
    IPAddress:
    -----------------------------------
    Win32_NetworkAdapterConfiguration instance
    -----------------------------------
    IPAddress:
    -----------------------------------
    Win32_NetworkAdapterConfiguration instance
    -----------------------------------
    IPAddress:
    -----------------------------------
    Win32_NetworkAdapterConfiguration instance
    -----------------------------------
    IPAddress:
    -----------------------------------
    Win32_NetworkAdapterConfiguration instance
    -----------------------------------
    IPAddress: 10.10.1.63
    -----------------------------------
    Win32_NetworkAdapterConfiguration instance
    -----------------------------------
    IPAddress:
    -----------------------------------
    Win32_NetworkAdapterConfiguration instance
    -----------------------------------
    IPAddress:
    -----------------------------------
    Win32_NetworkAdapterConfiguration instance
    -----------------------------------
    Now all the machines in the Network are going to start with the IP address 10.10.1.x so is there anyway I can filter the results and get only the bit I am looking for so for instance from this one my IP address would return: 10.10.1.63

    Thanks,
    Max
    M.Carpenter

    Server Admin for Wurm Online
    Wurm Online - A very unique and original MMO from Code Club AB
    https://www.youtube.com/watch?v=YQlYar2uHWAWurm Trailor


  2. #2
    Addicted Member
    Join Date
    Mar 2008
    Posts
    143

    Re: [2008] WMI Network Information (IP Address)

    Try changing the code from...

    Code:
    For Each queryObj As ManagementObject in searcher.Get()
    
        Console.WriteLine("-----------------------------------")
        Console.WriteLine("Win32_NetworkAdapterConfiguration instance")
        Console.WriteLine("-----------------------------------")
    
        If queryObj("IPAddress") Is Nothing Then
            Console.WriteLine("IPAddress: {0}", queryObj("IPAddress"))
        Else
            Dim arrIPAddress As String()
            arrIPAddress = queryObj("IPAddress")
            For Each arrValue As String In arrIPAddress
                Console.WriteLine("IPAddress: {0}", arrValue)
            Next
        End If
    Next
    to...

    Code:
    For Each queryObj As ManagementObject in searcher.Get()
        If Not(queryObj("IPAddress") Is Nothing) Then
            Dim arrIPAddress As String()
            arrIPAddress = queryObj("IPAddress")
            For Each arrValue As String In arrIPAddress
                Console.WriteLine(arrValue)
            Next
        End If
    Next
    Last edited by michaelerice; Sep 24th, 2008 at 09:35 AM.
    Shut up and eat your banana!

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    Re: [2008] WMI Network Information (IP Address)

    Hi thanks for the info almost there but not quite,

    It works almost but also picks up two ip addresses of:

    0.0.0.0


    So my final output is:

    0.0.0.0
    0.0.0.0
    10.10.1.63

    And for my program to work I can only have the one address. I tried changing the line:

    If Not (queryObj("IPAddress") Is Nothing) Then

    To:

    If Not (queryObj("IPAddress") Is Nothing Or queryObj("IPAddress") Is "0.0.0.0") Then

    but it still displays the 0.0.0.0's. Have you got a fix for this?


    Thanks,
    Max

    and a few variations but that is not valid
    M.Carpenter

    Server Admin for Wurm Online
    Wurm Online - A very unique and original MMO from Code Club AB
    https://www.youtube.com/watch?v=YQlYar2uHWAWurm Trailor


  4. #4
    Addicted Member
    Join Date
    Mar 2008
    Posts
    143

    Re: [2008] WMI Network Information (IP Address)

    Try...

    Code:
    For Each arrValue As String In arrIPAddress
        If arrValue <> "0.0.0.0" Then
            Console.WriteLine(arrValue)
        End If    
    Next
    This won't help you if there are more than one valid IP address.
    Shut up and eat your banana!

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    Re: [2008] WMI Network Information (IP Address)

    Ok thanks for the info I am just trying to play with that and get it working because at the moment it is only coming back with one ip but its coming back with 0.0.0.0

    For the sake of trying to make it easyier is their another way of getting an IP address rather than WMI where I can state that I only want an IP address returned if it begins with 10.10.1 ? because the front end will not be different.

    Thanks,
    Max
    M.Carpenter

    Server Admin for Wurm Online
    Wurm Online - A very unique and original MMO from Code Club AB
    https://www.youtube.com/watch?v=YQlYar2uHWAWurm Trailor


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