Solved

VB script that can display IP address and Host name

Posted on 2011-03-14
11
957 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
This is an explanation of a simple data model to help parse a JSON feed
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

770 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