Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 974
  • Last Modified:

VB script that can display IP address and Host name

Hi all, I am looking for a script that when run locally, a pop-up box will come up and display the users PC Name and IP Address.

I am not very good with VB But I was told this would be the preferred language of choice.

Any thoughts
0
OTNAdmin
Asked:
OTNAdmin
  • 5
  • 5
1 Solution
 
Pratima PharandeCommented:
Here is a small code sample using WScript to get the computer name, in addition to members of the ServerVariables collection for returning the domain name entered in the browser and the IP of the server.
 
<%
    Set pc = CreateObject("Wscript.Network")
    response.write pc.ComputerName
    Set pc = nothing
    response.write " (currently connected as " 
    response.write ucase(Request.ServerVariables("SERVER_NAME"))
    response.write " on " 
    response.write Request.ServerVariables("LOCAL_ADDR") & ")"
%>
 
Of course, you may want the actual computer name (from system properties), not the server name as requested through a web server (which could be an IP address, or an alias, or a fully qualified domain name). So, you can use WMI:
 
<%
    Set Loc = createobject("WBEMScripting.SWBEMLocator")
    Set nms = Loc.ConnectServer()
    WQL = "SELECT CSName FROM Win32_OperatingSystem"
    Set cs = nms.ExecQuery(WQL, "WQL", 48)
    For Each pc In cs
        Response.Write pc.CSName
    Next
    set cs = nothing: set nms = nothing: set loc = nothing
%>
0
 
jawa29Commented:
Hi OTNAdmin

If this is for the user to notify you of the information when asking for support have you considered using BGInfo?
http://technet.microsoft.com/en-us/sysinternals/bb897557

I use this to set the boot up wallpaper on our XP clients, with all the required info.

Jawa29
0
 
OTNAdminAuthor Commented:
Thanks for the response pratima_mcs, when I run the first one I get a error on line 2 error code 800a01A8 and when I try the other I get an erro on Line 6

Jawa29, we thought about it but management does not want us to be changing peoples wall paper
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jawa29Commented:
Ok I understand.

Try this bit of code.

Jawa29
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set cComputer = oWMIService.ExecQuery("Select * from Win32_ComputerSystem")

For Each oComputer In cComputer
	sHostName = UCase(oComputer.Name)
	sLogonUser = oComputer.UserName
Next
Set oComputer = Nothing

sTxt = "o0o HOSTNAME & USERNAME INFO o0o" & vbCrLf
sTxt = sTxt & "--------------------------------" & vbCrLf & vbCrLf
sTxt = sTxt & "Hostname : " & sHostName & vbCrLf & vbCrLf
sTxt = sTxt & "Username : " & sLogonUser

WScript.Echo sTxt

Open in new window

0
 
OTNAdminAuthor Commented:
Thanks, This is good, is there a way we can add thie IP address?
0
 
jawa29Commented:
Code with admendment for IP.

Jawa29


Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set cComputer = oWMIService.ExecQuery("Select * from Win32_ComputerSystem")

For Each oComputer In cComputer
	sHostName = UCase(oComputer.Name)
	sLogonUser = oComputer.UserName
Next
Set oComputer = Nothing

Set cIP = oWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
 
For Each IP in cIP
    If Not IsNull(IP.IPAddress) Then 
        For i=LBound(IP.IPAddress) to UBound(IP.IPAddress)
            sIPAddress = IP.IPAddress(i)
        Next
    End If
Next
Set cIP = Nothing


sTxt = "o0o HOSTNAME & USERNAME INFO o0o" & vbCrLf
sTxt = sTxt & "--------------------------------" & vbCrLf & vbCrLf
sTxt = sTxt & "Hostname : " & sHostName & vbCrLf & vbCrLf
sTxt = sTxt & "Username : " & sLogonUser & vbCrLf & vbCrLf
sTxt = sTxt & "IP Address : " & sIPAddress

WScript.Echo sTxt

Open in new window

0
 
OTNAdminAuthor Commented:
This is what I get when I run the script, not my IP
3-14-2011-11-56-54-AM.jpg
0
 
jawa29Commented:
Your running IPV6!!!

What IP range have you got, I could write it to pinpoint the first octet.

Jawa29
0
 
OTNAdminAuthor Commented:
I am not running v6 that is the thing.
0
 
jawa29Commented:
If you change line 15 from this

sIPAddress = IP.IPAddress(i)

to this

sIPAddress = sIPAddress & IP.IPAddress(i) & vbCrLf

It will list all the IPs, post the result.

Jawa29
0
 
OTNAdminAuthor Commented:
That is what i wanted, something that listed all the IP's Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now