Page 1 of 1 1
Topic Options
#130713 - 2004-12-07 09:09 AM Get ip address to server in logon script
mah01 Offline
Fresh Scripter

Registered: 2003-01-28
Posts: 22
Hi,
is there a way for the client to get the ip address of the server when it runs the logon script?

Kind regards,
Mattias

Top
#130714 - 2004-12-07 09:11 AM Re: Get ip address to server in logon script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Shouldn't be a real need to get the IP since the logon server should have a STATIC IP and you can get the name of the server that logged the client in with the @LServer macro.

Top
#130715 - 2004-12-07 09:14 AM Re: Get ip address to server in logon script
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
if there is a need though try : Ping() - checks for reply , or returns ip-address of remote host
_________________________



Top
#130716 - 2004-12-07 09:50 AM Re: Get ip address to server in logon script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Okay, if Jochen wants to go there

Here is an example to retrieve the requested information.

Code:
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')

Dim $LServerIP
$LServerIP=Ping(Join(Split(@LServer,"\\"),""),1,0,3)
? 'Logon Server IP is: ' + $LServerIP
? 'Logon Server name is: ' + Join(Split(@LServer,"\\"))

function Ping($Computer,$GetIP,optional $LoopCount,optional $TimeOut)
if $GetIP
dim $ip, $ipfile, $
$ipfile = @scriptdir + '\ip.txt'
shell '%Comspec% /q /e:1024 /c for /F "tokens=2 delims=[]" %%i IN ('+ chr(39)
+ '"ping ' + $Computer + ' -n 1 | find "]""' + chr(39) + ') do echo %%i >"' + $ipfile + '"'
$ = open(10,$ipfile,2) $ip = readline(10) $ = close(10) del $ipfile
if $ip
$Ping = $ip
else
$Ping = 'Bad IP address ' + $Computer + '!'
endif
exit 0
else
if $TimeOut
for $c = 0 to $LoopCount
shell '%Comspec% /C ping ' + $Computer + ' -n 1 -w ' + $TimeOut + ' | find /C "TTL=" > nul'
if @error = 0
$Ping = 1
exit 0
endif
next
else
for $c = 0 to $LoopCount
shell '%Comspec% /C ping ' + $Computer + ' | find /C "TTL=" > nul'
if @error = 0
$Ping = 1
exit 0
endif
next
endif
$Ping = 0
endif
endfunction


Top
#130717 - 2004-12-07 10:03 AM Re: Get ip address to server in logon script
mah01 Offline
Fresh Scripter

Registered: 2003-01-28
Posts: 22
Quote:

Shouldn't be a real need to get the IP since the logon server should have a STATIC IP and you can get the name of the server that logged the client in with the @LServer macro.



Thank you, but I need the ip address ( which isn't known by the client even though it is static ). Your function would probably work fine, but I need to know that the client will always have access to the ip address. I have only glanced at your function but I saw a timeout parameter and that makes me think that there is a possibility it might fail to recieve the ip address.

Quote:

if there is a need though try : Ping() - checks for reply , or returns ip-address of remote host



Thank you, I guess that perhaps there is no macro or function in kix to salve my problem.

I will probably try to write the ip address to a file and put it in the netlogon directory during installation of the server. That way the client can read the ip address from the file when it runs the logon script.

What do you think of that solution?

Kind regards,
Mattias


Edited by mah01 (2004-12-07 10:09 AM)

Top
#130718 - 2004-12-07 11:21 AM Re: Get ip address to server in logon script
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

What do you think of that solution?




I think it's a pretty awful idea. Why do you need the IP address explicitly, rather than the machine name?

Top
#130719 - 2004-12-07 11:37 AM Re: Get ip address to server in logon script
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Quote:

I have only glanced at your function but I saw a timeout parameter and that makes me think that there is a possibility it might fail to recieve the ip address.





nah, that timeout is just an optional parameter for the maximum duration of trying to get a reply ... the resolution of course relies on the systems ability to resolve the IP from host name, speak DNS, WINS or a hosts file



Edited by Jochen (2004-12-07 11:38 AM)
_________________________



Top
#130720 - 2004-12-07 12:25 PM Re: Get ip address to server in logon script
mah01 Offline
Fresh Scripter

Registered: 2003-01-28
Posts: 22
Quote:

I think it's a pretty awful idea. Why do you need the IP address explicitly, rather than the machine name?



Ofcaurse it's a bad solution, that's why I've asked for a better one here but at least it is robust. The client will always be able to get the ip address.

I need the ip address to setup the timesync between the client ( win xp ) and the server ( win nt4 ). But that's beside the scope of this forum.

Top
#130721 - 2004-12-07 01:13 PM Re: Get ip address to server in logon script
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Quote:

I need the ip address to setup the timesync between the client ( win xp ) and the server ( win nt4 ). But that's beside the scope of this forum.




1. The best solution then would be what you already came up with. Awful? Who cares! ... Well, ok, an ini-file would fit better to prevent file lock issues!! See read/writeprofilestring functions.

2. What makes you think that the scope of KiXtart.org is reduced to KiXtart scripts?
_________________________



Top
#130722 - 2004-12-07 01:56 PM Re: Get ip address to server in logon script
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Here is a tidier way to get the IP address:
Code:
$oWMI = GetObject("winmgmts:\\.\root\cimv2")
$colPings=$oWMI.ExecQuery("Select * From Win32_PingStatus where Address = '"+SubStr(%LOGONSERVER%,3)+"'")

For Each $oStatus in $colPings
"Logon server IP address: " $oStatus.ProtocolAddress ?
Next


Top
#130723 - 2004-12-07 01:57 PM Re: Get ip address to server in logon script
mah01 Offline
Fresh Scripter

Registered: 2003-01-28
Posts: 22
Quote:


1. The best solution then would be what you already came up with. Awful? Who cares! ... Well, ok, an ini-file would fit better to prevent file lock issues!! See read/writeprofilestring functions.

2. What makes you think that the scope of KiXtart.org is reduced to KiXtart scripts?




Thank you for the tip about the ini-file, that's what I'll use.

Oops, I meant to say thread ofcaurse , not forum

Top
#130724 - 2004-12-07 02:12 PM Re: Get ip address to server in logon script
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Richard,

this might be tidier but if I run this on my Machine (W2K SP4) it returns nothing ... @error of GetObject is 0, substr of %LOGONSERVER% is correct

This is the second time that a cimv2 script fails for me this week
For me it turns out that Wee Em Aye is not that reliable
_________________________



Top
#130725 - 2004-12-07 03:02 PM Re: Get ip address to server in logon script
mah01 Offline
Fresh Scripter

Registered: 2003-01-28
Posts: 22
Hallo again,

do you know if there is a simple way to find out the ip address of the computer the script is executing on?

Kind regards,
Mattias

Top
#130726 - 2004-12-07 03:05 PM Re: Get ip address to server in logon script
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Have a look at the KiXtart builtin macros.

@IPADDRESS0 will do in most cases.

Top
#130727 - 2004-12-07 03:51 PM Re: Get ip address to server in logon script
mah01 Offline
Fresh Scripter

Registered: 2003-01-28
Posts: 22
Quote:

Have a look at the KiXtart builtin macros.

@IPADDRESS0 will do in most cases.



Thank you, I'll try that.

Top
#130728 - 2004-12-07 08:08 PM Re: Get ip address to server in logon script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Quote:

Well, ok, an ini-file would fit better to prevent file lock issues




If you're only reading the file there is no contention whether it is TXT or INI the file contention comes when you try to open the file for write access when someone else tries at the same time.

That said, yes the .ini method though would be easier to use I think.

Top
#130729 - 2004-12-08 01:25 AM Re: Get ip address to server in logon script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
If timeservers are properly implemented, then you will always have redundant second-level time servers as described in the relevant Microsoft whiepapers dealing with time synchronization in an windows NT4 or AD environment.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 1452 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.078 seconds in which 0.029 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