Forum Discussion

vishwas_n's avatar
vishwas_n
Occasional Contributor
12 years ago

IP Address fetching for remote machine using C#Script

Fellas,



Am using this piece of code to fetch the IP ...



wmiServ["ExecQuery"]("SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'");



Which is returning 'null'

I tried with given my NIC card description with no imprvements.

\

wmiServ["ExecQuery"]("SELECT IPAddress FROM Win32_NetworkAdapterConfiguration where IPEnabled='True' and Description ='Intel(R) 82579LM Gigabit Network Connection'");



Help this novice guys ...




 



  • Hi Vishwas,


     


    The following code, posted in this thread, works for me:




    Sub LogIPAddress 


      strQuery = "select * from Win32_NetworkAdapterConfiguration where IPEnabled=True" 


      Set colItems = GetObject("winmgmts:").ExecQuery(strQuery) 


      Log.Message sys.HostName 


      For Each objItem In colItems 


        Log.Message(objItem.DNSHostName) 


        Log.Message(objItem.IPAddress(0))  


      Next  


    End Sub 




     


    If it doesn't work, check the WMI settings on the computer.


     

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Vishwas,


     


    The following code, posted in this thread, works for me:




    Sub LogIPAddress 


      strQuery = "select * from Win32_NetworkAdapterConfiguration where IPEnabled=True" 


      Set colItems = GetObject("winmgmts:").ExecQuery(strQuery) 


      Log.Message sys.HostName 


      For Each objItem In colItems 


        Log.Message(objItem.DNSHostName) 


        Log.Message(objItem.IPAddress(0))  


      Next  


    End Sub 




     


    If it doesn't work, check the WMI settings on the computer.


     

  • vishwas_n's avatar
    vishwas_n
    Occasional Contributor


    It is returning IP in a[1], am unable to display as given below ...

    a is an Object. While a[1] and a[0] are string.





    var
    a = WmiQuery(".","","","Testing20")



    Log["Message"](a[1])