aks
aks

Reputation: 1859

Finding IP Address of my computer using VBScript

How can I find the IP Address of my computer using VBScript?

Upvotes: 1

Views: 27361

Answers (2)

Shubham Verma
Shubham Verma

Reputation: 9961

This is how you can display the IP address in VB script:

Function getIPAddress()
    'Get your Public IP
    dim NIC, Nic, StrIPAdd, ComputerName, ipMessage
    Set NIC = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
    For Each Nic in NIC
        if Nic.IPEnabled then
            StrIPAdd = Nic.IPAddress(0)
            Set WshNetwork = WScript.CreateObject("WScript.Network")
            ComputerName= WshNetwork.Computername
            ipMessage="IP Address: "&StrIPAdd & vbNewLine &"Computer Name: " &ComputerName & vbNewLine &"Date:" &currentDate
        End if
    Next
    getIPAddress=ipMessage
End Function

Call you function:

ipMessage =getIPAddress()
WScript.Echo ipMessage.

Upvotes: 0

RubenDiaz
RubenDiaz

Reputation: 61

This example shows the ip configured and the computer name:

dim NIC1, Nic, StrIP, CompName

Set NIC1 =     GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")

For Each Nic in NIC1

    if Nic.IPEnabled then
        StrIP = Nic.IPAddress(0)

        Set WshNetwork = WScript.CreateObject("WScript.Network")
        CompName= WshNetwork.Computername

        MsgBox "IP Address:  "&StrIP & vbNewLine _
            & "Computer Name:  "&CompName,4160,"IP Address and Computer Name"

        wscript.quit
    End if
Next

Upvotes: 6

Related Questions