Solved

VB script that can display IP address and Host name

Posted on 2011-03-14
11
954 Views
Last Modified: 2012-08-14
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
Comment
Question by:OTNAdmin
  • 5
  • 5
11 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35127782
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
 
LVL 8

Expert Comment

by:jawa29
ID: 35127867
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
 

Author Comment

by:OTNAdmin
ID: 35128245
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
 
LVL 8

Expert Comment

by:jawa29
ID: 35128375
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
 

Author Comment

by:OTNAdmin
ID: 35128670
Thanks, This is good, is there a way we can add thie IP address?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:jawa29
ID: 35128960
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
 

Author Comment

by:OTNAdmin
ID: 35129776
This is what I get when I run the script, not my IP
3-14-2011-11-56-54-AM.jpg
0
 
LVL 8

Expert Comment

by:jawa29
ID: 35129852
Your running IPV6!!!

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

Jawa29
0
 

Author Comment

by:OTNAdmin
ID: 35129938
I am not running v6 that is the thing.
0
 
LVL 8

Accepted Solution

by:
jawa29 earned 500 total points
ID: 35129970
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
 

Author Comment

by:OTNAdmin
ID: 35130725
That is what i wanted, something that listed all the IP's Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now