Page 1 of 1 1
Topic Options
#167090 - 2006-09-08 02:22 PM Remote IP-Address
private_meta Offline
Getting the hang of it

Registered: 2006-07-27
Posts: 80
Loc: Austria
Hello again.

I'm having trouble finding out the IP-Address of a workstation that i connect remotley.
Is there a way to pinpoint the IP-Address a computer uses via WMI?
When i'm reading out the IP-Addresses in Win32_NetworkAdapterConfiguration i'm not able to determine the right Address because there can be an address for both the built in adapter and for WLAN, and, especially on the computer i'm making the script there are 5 Adapters that say "Ethernet 802.3", so it's not possible for me to determine which Adapter is the right one and where i can get it from.
I'm thinking about making a ping on the hostname and extracting the IP from there, but there has to be an easier way...

Does anyone know what i can do there to make it possible via WMI?

greets
meta
_________________________
-=If you absolutly believe you can make up talent with hard work, there is no limit to what you can't achieve.=-

Top
#167091 - 2006-09-08 02:48 PM Re: Remote IP-Address
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Maybe LookupIP?
Top
#167092 - 2006-09-08 05:04 PM Re: Remote IP-Address
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
You don't know the host-name or dns-name?
Top
#167093 - 2006-09-08 05:25 PM Re: Remote IP-Address
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Using EnumNetworkConnections() and GetIPOptions() should work.

The example below is from the GetIPOptions() header. It should get you started in the right direction.


Code:
 
break on
$remotepc="computername"
for each $nc in Enumnetworkconnections(3,$remotepc)
$ConnectionName=split($nc,",")[0]
$MACAddress=split($nc,",")[1]
$AdapterName=split($nc,",")[2]
? " Connection Name: " + $connectionname
? " MACAddress: " + $MACAddress
? " Adapter Name: " + $AdapterName
? " Mac Address: " + getipoptions("Macaddress",$remotepc,$macaddress)
? " Static Address: " + getipoptions("StaticIP",$remotepc,$macaddress)
? " DHCP Enabled: " + getipoptions("DHCPEnabled",$remotepc,$macaddress)
? " IPaddress/SM: " + getipoptions("IPAddress",$remotepc,$macaddress)
? " IPaddress0/SM: " + getipoptions("IPAddress0",$remotepc,$macaddress)
? " IPaddress1/SM: " + getipoptions("IPAddress1",$remotepc,$macaddress)
? " IPaddress2/SM: " + getipoptions("IPAddress2",$remotepc,$macaddress)
? " IPaddress3/SM: " + getipoptions("IPAddress3",$remotepc,$macaddress)
? " DefaultGW: " + getipoptions("DefaultGW",$remotepc,$macaddress)
? " DNS Servers: " + getipoptions("DNSServers",$remotepc,$macaddress)
? " WINS Servers: " + getipoptions("WINSServers",$remotepc,$macaddress)
? " DNSSuffix: " + getipoptions("DNSDomain",$remotepc,$macaddress)
? " DNS Search Order: " + getipoptions("DNSDomainSuffixSearchOrder",$remotepc,$macaddress)
? " DHCP Server: " + getipoptions("DHCPServer",$remotepc,$macaddress)
? "DHCP Lease Obtained: " + getipoptions("DHCPLeaseObtained",$remotepc,$macaddress)
? " DHCP Lease Expires: " + getipoptions("DHCPLeaseExpires",$remotepc,$macaddress)
? "---------------"
next



Top
#167094 - 2006-09-11 09:32 AM Re: Remote IP-Address
private_meta Offline
Getting the hang of it

Registered: 2006-07-27
Posts: 80
Loc: Austria
Witto: LookUpIP does not work for me at all

Allen: GetIPOptions is quite nice, but alas, it's not that useful as i cannot get the IP-Addresses of remote XP Computers because i cannot access their WMI (see WMI help Post by me in this Forum). I think i need to go with the ping reply anyways
_________________________
-=If you absolutly believe you can make up talent with hard work, there is no limit to what you can't achieve.=-

Top
#167095 - 2006-09-11 12:32 PM Re: Remote IP-Address
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
LookUpIP() and LookupName() requires WinXP or newer, but it does a ping on the target.

Do you have access to the DHCP server? if it is a MS dhcp, you can get the assigned IPs and hostnames that way.

Top
#167096 - 2006-09-11 02:19 PM Re: Remote IP-Address
private_meta Offline
Getting the hang of it

Registered: 2006-07-27
Posts: 80
Loc: Austria
The Script runs on a Win2k-Workstation.

I've solved the problem, though it might be a bit rough as i'm not that able to hand back a multidimensional array (maybe you can help there)

Code:

;FUNCTION NetViewSH()
;
;ACTION Gets Computernames, Descriptions and IPs from a network without WMI-Usage
;
;VERSION 0.9
;
;KIXTART VER 4.53
;
;AUTHOR Andreas "private_meta"
;
;SYNTAX $ = NetViewSH("Domain")
;
;PARAMETERS Domain
; Domain Name for a network, optional
;
;RETURN Nothing
;
;REMARKS none
;
;DEPENDENCIES working network ;)
;
;EXAMPLE
; NetViewSH()
; FOR $i = 1 TO UBOUND($net_names)
; $net_names[$i] + " " + $net_descr[$i] + " " + $net_ips[$i] ?
; NEXT
;
;KIXTART BBS none yet ;)
;

Function NetViewSH(optional $domain)
GLOBAL $net_names[255]
GLOBAL $net_descr[255]
GLOBAL $net_ips[255]
DIM $REDIM $REDIM = 255
DIM $i $i = 0
DIM $j $j = 0
DIM $tempfile $tempfile = "%temp%\netview2.pmt"
DIM $tempfile1 $tempfile1 = "%temp%\netview3.pmt"
IF $domain
$domain = "/domain:$domain"
ENDIF
IF Exist($tempfile)
DEL $tempfile
ENDIF
SHELL '%comspec% /c net view $domain >"$tempfile"'
IF @error = 0
IF Open(10,$tempfile) = 0
DO
$line = ReadLine(10) ; skip header
UNTIL SUBSTR($line,1,2) = "\\"
WHILE @error = 0
$net_names[$i] = RTrim(SubStr($line,3,InStr($line," ")-1))
$net_descr[$i] = LTrim(RTrim(SubStr($line,19,60)))
SHELL "%comspec% /c ping -n 1 " + $net_names[$i] + " > " + "$tempfile1"
IF Open(9,$tempfile1) = 0
DO
$line1 = ReadLine(9)
UNTIL SUBSTR($line1,1,4) = "Ping" OR @ERROR=-1
IF @ERROR=-1
$net_ips[$i] = "0.0.0.0"
ELSE
$net_ips[$i] = SPLIT(SPLIT($line1,"[")[1],"]")[0]
ENDIF
ENDIF
$x=CLOSE(9)
$i=$i+1
IF $i = $REDIM
$REDIM=$REDIM*2
REDIM $net_names[$REDIM]
ENDIF
$line = ReadLine(10)
Loop
$x=Close(10)
DEL $tempfile
DEL $tempfile1
IF $i
REDIM preserve $net_names[$i-4]
;$netview = $net_names
EXIT @error
ENDIF
FOR EACH $item IN $net_names $item ? NEXT
ENDIF
ENDIF
;$netview = $net_names
EXIT @error
ENDFUNCTION



Edited by private_meta (2006-09-13 12:07 PM)
_________________________
-=If you absolutly believe you can make up talent with hard work, there is no limit to what you can't achieve.=-

Top
#167097 - 2006-09-12 06:11 AM Re: Remote IP-Address
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
There is already a NetView UDF, I suggest you use a unique name.
_________________________
There are two types of vessels, submarines and targets.

Top
#167098 - 2006-09-12 06:31 AM Re: Remote IP-Address
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
I don't think you can use $REDIM can you? I thought that was a keyword.
Top
#167099 - 2006-09-12 08:28 AM Re: Remote IP-Address
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Doc,
I would not promote the habit to use vars like $ReDim either, but it seems to work:
Code:

If NOT @LOGONMODE
Break On
EndIf
Dim $SO
$SO = SetOption("Explicit","On")
$SO = SetOption("NoMacrosInStrings","On")
$SO = SetOption("NoVarsInStrings","On")
$SO = SetOption("WrapAtEOL","On")

Dim $ReDim[2]
$ReDim = Split("a,b,c",",")
ReDim Preserve $ReDim[3]
$ReDim[3] = "d"
For Each $SO In $ReDim
? $SO
Next
? "KiX Version: " + @KIX
? "KiX Executable: " @SCRIPTEXE


Output on screen
Code:

a
b
c
d
KiX Version: 4.53 Release Candidate 1
KiX Executable: KIX32.EXE


Top
#167100 - 2006-09-13 12:06 PM Re: Remote IP-Address
private_meta Offline
Getting the hang of it

Registered: 2006-07-27
Posts: 80
Loc: Austria
I've used the redim part from someone else >_<;

I've edited the name to be Unique (tho not quite spirited)

Can anyone give me a hint about putting that into multi-dimensional arrays? i'm not that used to that.


P.S.: *phew* i'm damn happy i've pasted it here on monday... network backup failed for a couple of days and my files are gone (last state: friday)


Edited by private_meta (2006-09-13 12:15 PM)
_________________________
-=If you absolutly believe you can make up talent with hard work, there is no limit to what you can't achieve.=-

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 675 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.034 seconds in which 0.013 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org