|
-
Jul 23rd, 2008, 09:11 AM
#1
[SCRIPT SAMPLE] Get the ip address of a computer.
This is the script we use.
PHP Code:
On Error Resume Next
Dim WSHShell, RegKey, strComputer
Set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName"
strComputer = WSHShell.RegRead(RegKey)
IPDetails = "Error reading IP address. Computer name incorrect."
Set objWMIService = GetObject ("winmgmts:" & "{impersonationLevel=impersonate}!\\"& strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objAdapter in colAdapters
If Not IsNull(objAdapter.IPAddress) Then
if LEN(objAdapter.IPAddress)>0 Then
If IPDetails="Error reading IP address. Computer name incorrect." Then
IPDetails = "NIC Description: " & objAdapter.Description
else
IPDetails = IPDetails & vbcrlf & vbcrlf & "NIC Description: " & objAdapter.Description
End If
IPDetails = IPDetails & vbcrlf & "Physical address : " & objAdapter.MACAddress
For i = LBound(objAdapter.IPAddress) To UBound(objAdapter.IPAddress)
IPDetails = IPDetails & vbcrlf & "IP address : " & objAdapter.IPAddress(i)
Next
If Not IsNull(objAdapter.IPSubnet) Then
For i = LBound(objAdapter.IPSubnet) To UBound(objAdapter.IPSubnet)
IPDetails = IPDetails & vbcrlf & "Subnet : " & objAdapter.IPSubnet(i)
Next
End If
If Not IsNull(objAdapter.DefaultIPGateway) Then
For i = LBound(objAdapter.DefaultIPGateway) To UBound(objAdapter.DefaultIPGateway)
IPDetails = IPDetails & vbcrlf & "Default gateway : " & objAdapter.DefaultIPGateway(i)
Next
End If
If Not IsNull(objAdapter.DNSServerSearchOrder) Then
For i = LBound(objAdapter.DNSServerSearchOrder) To UBound(objAdapter.DNSServerSearchOrder)
IPDetails = IPDetails & vbcrlf & "DNS server : " & objAdapter.DNSServerSearchOrder(i)
Next
End If
End If
End If
Next
if IPDetails = "Error reading IP address. Computer name incorrect." then
q=msgbox(UCase(strComputer) & vbcrlf & vbcrlf & IPDetails,48,"Display IP Config")
Else
q=msgbox(UCase(strComputer) & vbcrlf & vbcrlf & IPDetails,64,"Display IP Config")
End If
Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
save a blobFileStreamDataTable To Text Filemy blog
-
Nov 21st, 2008, 03:27 PM
#2
New Member
Re: [SCRIPT SAMPLE] Get the ip address of a computer.
Thank you very much for the sample code...although I'm not a savy programmer, can you please tell me how to add text in front of the computer name?
Thank you!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|