Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB script that can display IP address and Host name

Posted on 2011-03-14
11
Medium Priority
?
970 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Starting up a Project

721 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