Solved

VB script that can display IP address and Host name

Posted on 2011-03-14
11
952 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 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…

708 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

17 Experts available now in Live!

Get 1:1 Help Now