Results 1 to 2 of 2

Thread: [SCRIPT SAMPLE] Get the ip address of a computer.

  1. #1

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Resolved [SCRIPT SAMPLE] Get the ip address of a computer.

    This is the script we use.
    PHP Code:
    On Error Resume Next
    Dim WSHShell
    RegKeystrComputer

    Set WSHShell 
    CreateObject("WScript.Shell")
    RegKey "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName"
    strComputer WSHShell.RegRead(RegKey)

    IPDetails "Error reading IP address. Computer name incorrect."

    Set objWMIService GetObject ("winmgmts:" "{impersonationLevel=impersonate}!\\"strComputer "\root\cimv2")
    Set colAdapters objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")

    For 
    Each objAdapter in colAdapters
        
    If Not IsNull(objAdapter.IPAddressThen
            
    if LEN(objAdapter.IPAddress)>0 Then
            
    If IPDetails="Error reading IP address. Computer name incorrect." Then
                IPDetails 
    "NIC Description: " objAdapter.Description
            
    else
                
    IPDetails IPDetails vbcrlf vbcrlf "NIC Description: " objAdapter.Description
            End 
    If    

            
    IPDetails IPDetails vbcrlf "Physical address : " objAdapter.MACAddress

            
    For LBound(objAdapter.IPAddressTo UBound(objAdapter.IPAddress)
                
    IPDetails IPDetails vbcrlf "IP address          : " objAdapter.IPAddress(i)
            
    Next

            
    If Not IsNull(objAdapter.IPSubnetThen
                
    For LBound(objAdapter.IPSubnetTo UBound(objAdapter.IPSubnet)
                    
    IPDetails IPDetails vbcrlf "Subnet                : " objAdapter.IPSubnet(i)
                
    Next
            End 
    If

            If 
    Not IsNull(objAdapter.DefaultIPGatewayThen
                
    For LBound(objAdapter.DefaultIPGatewayTo UBound(objAdapter.DefaultIPGateway)
                    
    IPDetails IPDetails vbcrlf "Default gateway : " objAdapter.DefaultIPGateway(i)
                
    Next
            End 
    If

            If 
    Not IsNull(objAdapter.DNSServerSearchOrderThen
                
    For LBound(objAdapter.DNSServerSearchOrderTo UBound(objAdapter.DNSServerSearchOrder)
                    
    IPDetails IPDetails vbcrlf "DNS server         : " objAdapter.DNSServerSearchOrder(i)
                
    Next
            End 
    If
            
    End If
        
    End If
    Next

    if IPDetails "Error reading IP address. Computer name incorrect." then
        q
    =msgbox(UCase(strComputer) & vbcrlf vbcrlf  IPDetails,48,"Display IP Config")
    Else
        
    q=msgbox(UCase(strComputer) & vbcrlf vbcrlf  IPDetails,64,"Display IP Config")
    End If 
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  2. #2
    New Member
    Join Date
    Nov 2008
    Posts
    1

    Thumbs up Re: [SCRIPT SAMPLE] Get the ip address of a computer.

    Thank you very much for the sample code...although I'm not a savy programmer, can you please tell me how to add text in front of the computer name?

    Thank you!!

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