 |
|
 |
Here's a simple way to get you're IP address when you have several network cards:
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration ")
DIP = ""
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) _
to UBound(IPConfig.IPAddress)
If Not (IPConfig.IPAddress(i)="0.0.0.0") Then
IPAddr = IPAddr + IPConfig.IPAddress(i) + vbNewLine
End if
Next
end if
next
msgbox "IP Address for computer :" & CName & vbNewLine & IPAddr,vbOKOnly,"Computer Information"
|
|
|
|
 |
|
 |
You didn't take for consideration what if you have a different subfolder, other then "\1\"? If I have "\10\" or "\12\" only? It will never work..
|
|
|
|
 |
|
 |
'The script have some changes to find out every network card...is still uncomplet at all but fully functional 'below reads the registry to check in the Bindings list for TCPIP to check which card to use 'modified by LeuCos ... v 1.2 !? ' Script to retrieve the current IP Address on the first network card. ' ' (c) 2002 A.J. Elsinga ' anne.jan@network-direct.com ' ' "version 1.1"*** 'Option explicit ' force all variables to be declared ' ************************************************************ ' *** Start of functions and procedures *** ' ************************************************************ Function GetIPAddress ' This function retrieves the IP Address from the registry ' It gets it from the CurrentControlSet, so even when using DHCP ' it returns the correct IP Address ' Declare variables Dim z, x 'pointers Dim key Dim IPAddress Dim tempIPAddress Dim sh Dim TCPIPKey Dim InterfaceTmp Dim Interface Dim IPAddressKey Set Sh = CreateObject("WScript.Shell") TCPIPKey="HKLM\SYSTEM\CurrentControlSet\Services\TCPIP\" InterfaceTmp=sh.regread(TCPIPKey&"Linkage\Bind") While UBound(InterfaceTmp)-1 => z If InStr(InterfaceTmp(z), "{") Then 'may i use Right, but this crashes...i don´t know whay? Interface=Interface & StrReverse(Left(StrReverse(InterfaceTmp(z)), instr(StrReverse(InterfaceTmp(z)), "{\"))) & "#" End If z=z+1 Wend Interface=Split(Interface, "#") t=UBound(Interface) While UBound(Interface)-1 => x ' First check which network card to use IPAddressKey=TCPIPKey+"Parameters\Interfaces\"+Interface(x)+"\" ' Now read the IP Address from that card tempIPAddress=sh.RegRead (IPAddressKey+"IPAddress") IPAddress=tempIPAddress(0) ' If the address="0.0.0.0" then asume that this is DHCP If IPAddress="0.0.0.0" Then If (sh.RegRead(IPAddressKey+"EnableDHCP")=1) Then On Error Resume Next IPAddress=sh.RegRead (IPAddressKey+"DHCPIPAddress") If Not Err.Number <> 0 Then x=UBound(Interface) End If End If End If x=x+1 Wend ' the IP addresss is now readable from ipaddress GetIPAddress=IPAddress End Function
Function GetIPOctet (nOctet) ' This function retrieves a given octet out of the IP Address Dim IPAddress IPAddress=Split(GetIPAddress, ".", 4) GetIPOctet=IPAddress(nOctet-1) End Function
very good work lady...i searching for some thing like that 'cuz wmi don´t work in some pcs!? it´s a possible...i have some problems with first version ... i had a old net card but i´ve removed them so they informations is on the registry and it´s crashes when try to find a broken informations...i add a error handle that works 2gether with pointer that is used to make a card select...but...it´s not useful when u use 2 functional net cards that use diferent ip's. i expect some changes...
|
|
|
|
 |
|
 |
Hi,
Ok, but if you are behind a router?...
|
|
|
|
 |
|
 |
can u tell me how can enter or know the detail of a compurt if a know the ip address of tht computer.can u tell me how to find out the complete address(physical address like house no,street name etc)through the ip address of tht person??????????
let me know everything tht is important.
|
|
|
|
 |
|
 |
Hi,
I need a simple script, with my HTML page (say index.html) when anyone loads my page on his browser it sends request to my server soft. listening on port 8888 using my static IP (xx.xx.xx.xx) so i can track what the user's IP is.
If possible please email me your comments on it to bluebeephrank@aol.com
Thanks.
|
|
|
|
 |
|
 |
Hi .I would like to get the IP Address (with Dhcp) from a workstation(Win98). How can i do it? Thanks
|
|
|
|
 |
|
 |
' This way also gets VPN address
set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
for each IPConfig in IPConfigSet
if Not IsNull(IPConfig.IPAddress) then
for i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
next
end if
next
|
|
|
|
 |
|
 |
This is indeed a better way to do this, but how do you retrieve the IP-address from the card you want?
For example: We need a variable set based on the IP-address for a certain site (I know, we can use the site var or registry key, but this isn't always the correct site).
|
|
|
|
 |
|
 |
Well, there are a number of things that you can determine from the "Win32_NetworkAdapterConfiguration" object. I found a description of the object at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/r_32hard4_15pq.asp
You could add any of the properties listed here to the WHERE clause, or just select out the ones that you want (for example, in the example below I grab "Caption" as well).
set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select IPAddress, Caption from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
for each IPConfig in IPConfigSet
if Not IsNull(IPConfig.IPAddress) then
for i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i) & "-" & IPConfig.Caption
next
end if
next
|
|
|
|
 |
|
 |
The script below reads the registry to check in the Bindings list for TCPIP to check which card to use.
' Script to retrieve the current IP Address on the first network card. ' ' (c) 2002 A.J. Elsinga ' anne.jan@network-direct.com ' ' version 1.1 option explicit ' force all variables to be declared ' ************************************************************ ' *** Start of functions and procedures *** ' ************************************************************ Function GetIPAddress ' This function retrieves the IP Address from the registry ' It gets it from the CurrentControlSet, so even when using DHCP ' it returns the correct IP Address ' Declare variables Dim key Dim IPAddress Dim tempIPAddress Dim sh Dim TCPIPKey Dim InterfaceTmp, InterfaceTmp1 Dim Interface Dim IPAddressKey Set Sh = CreateObject("WScript.Shell") TCPIPKey="HKLM\SYSTEM\CurrentControlSet\Services\TCPIP\" InterfaceTmp=sh.regread(TCPIPKey&"Linkage\Bind") InterfaceTmp1=split(InterfaceTmp(0),"\") Interface=InterfaceTmp1(2) ' First check which network card to use IPAddressKey=TCPIPKey+"Parameters\Interfaces\"+Interface+"\" ' Now read the IP Address from that card tempIPAddress=sh.RegRead (IPAddressKey+"IPAddress") IPAddress=tempIPAddress(0) ' If the address="0.0.0.0" then asume that this is DHCP If IPAddress="0.0.0.0" Then If (sh.RegRead(IPAddressKey+"EnableDHCP")=1) Then IPAddress=sh.RegRead (IPAddressKey+"DHCPIPAddress") End If End if ' the IP addresss is now readable from ipaddress GetIPAddress=IPAddress End Function
Function GetIPOctet (nOctet) ' This function retrieves a given octet out of the IP Address Dim IPAddress IPAddress=GetIPAddress GetIPOctet=IPAddress(nOctet-1) End Function
|
|
|
|
 |
|
 |
There is a lot of discussion on the net for determinig the ip address of a computer with/without DHCP, WINS etc on different OS such as Win95, NT/NT 2000. From all this, I found that only way to determine IP address correctly is to use the same method(s) used by ipconfig. So it is probably safest to run ipconfig and parse the output.
|
|
|
|
 |
|
 |
You're right. I overlooked this. I rewrote the script. It now uses the method as IPConfig does (I hope, grinn).
A.J.
|
|
|
|
 |
|
 |
What if user without privilege to read the registry?Would this script still works,I have tested it yet,but I do trust there are still some problems on your code.(Could these subkey resides on different location with different MS OS version?If so,do a little system check,also verify the subkey existence, some user might accidentially del these keys,then your script would become useless at this point.If I have any thing wrong,point it out plz;)
Welcome to EMAIL me with any questions.
|
|
|
|
 |
|
 |
I have used winsock, registry, and ipconfig (i am using 2000) and all seem to work but i find the quickest way is to just use the functions built right into the DLL files. currently i found some code here that were able to solve all the problems i was having coding into the DLL's and now it works flawlessly, finds the IP for DHCP and Static Addresses. Right now we are running a lab with approx 98 computers and we have a little client program accessing the registry as well as DLL files to find the username, computer name, mac address, and mac address. This saves the output to a file at every specified interval, then the frontend program parses through this file and based on the information there displays visually who is sitting at which computer. Its kind of a monitoring program to see max usage and which computers are used the most. The method in this thread though i have found to work great for what i need and i thank the writer, this code executes much faster than mine and is more concise. Thank you, and before i forget thank you to ALL programmers online that have helped me presently, in the past and in the future. Thank you all
|
|
|
|
 |
|
 |
I tried this script on a winXP pro, and I got an "unable to open registry key" on line 51.
|
|
|
|
 |