#130713 - 2004-12-07 09:09 AM
Get ip address to server in logon script
|
mah01
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
|
|
|
|
#130715 - 2004-12-07 09:14 AM
Re: Get ip address to server in logon script
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
|
Top
|
|
|
|
#130716 - 2004-12-07 09:50 AM
Re: Get ip address to server in logon script
|
NTDOC
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
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
   
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
|
|
|
|
#130720 - 2004-12-07 12:25 PM
Re: Get ip address to server in logon script
|
mah01
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
|
|
|
|
#130722 - 2004-12-07 01:56 PM
Re: Get ip address to server in logon script
|
Richard H.
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
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
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
|
Top
|
|
|
|
#130725 - 2004-12-07 03:02 PM
Re: Get ip address to server in logon script
|
mah01
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
|
|
|
|
#130727 - 2004-12-07 03:51 PM
Re: Get ip address to server in logon script
|
mah01
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
   
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1110 anonymous users online.
|
|
|