#95052 - 2002-11-02 12:41 AM
Re: Trigger Your Logon Script - WMI
|
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Doc,
I am intersted in this too.
Kent
|
Top
|
|
|
|
#95054 - 2002-11-02 04:58 AM
Re: Trigger Your Logon Script - WMI
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Here we go...
I've been testing from home dialing into VPN. Seems to work just fine.
As far as I can tell, it doesn't hog resources much. Every four seconds I see a slight jump in CPU utilization. Memory use doesn't look like its climbing. I'll leave it run overnight and let you know tomorrow.
Here's the code...
code:
Break On Cls $asSubnetList="xxx.xxx.xxx.xxx/255.255.255.0","xxx.xxx.xxx.xxx/255.255.255.0" $objEvents = GetObject("winmgmts:\\.\root\cimv2").ExecNotificationQuery ("SELECT TargetInstance.Name FROM __InstanceOperationEvent WITHIN " +"4 WHERE TargetInstance ISA 'Win32_NetworkAdapterConfiguration'") Do $objConnectEvent = $objEvents.nextevent $aIPAddress=$objConnectEvent.TargetInstance.IPAddress For Each $sAddress in $aIPAddress If VarType($sAddress)=8 $bFoundMatch=IsInIPRange($sAddress,$asSubnetList) EndIf Next If $bFoundMatch=1 Sleep 5 Run "KiX32 \\testserver\kixtest\LogonScriptSmpl.kix" EndIf Until @ERROR function isiniprange($ipaddress,$iprangearray) Dim $iprange, $networkid, $subnetmask, $bit if $ipaddress='' exit 87 endif $ipaddress=binaryip($ipaddress)
for each $iprange in $iprangearray
if instr($iprange,'/') $iprange=split($iprange,'/') $networkid=binaryip($iprange[0])
if instr($iprange[1],'.') $subnetmask=binaryip($iprange[1]) else $subnetmask='' for $bit=1 to val($iprange[1]) $subnetmask=$subnetmask+'1' next for $bit=(val($iprange[1])+1) to 32 $subnetmask=$subnetmask+'0' next endif
if isinsubnet($ipaddress,$networkid,$subnetmask) $isiniprange=1 return else $isiniprange=0 endif endif next endfunction function isinsubnet($ipaddress,$networkid,$subnetmask) Dim $maskedip, $bit if instr($ipaddress,'.') $ipaddress=binaryip($ipaddress) endif if instr($networkid,'.') $networkid=binaryip($networkid) endif if instr($subnetmask,'.') $subnetmask=binaryip($subnetmask) endif $maskedip=ipmask($ipaddress,$subnetmask) if $maskedip=$networkid $isinsubnet = 1 else $isinsubnet = 0 endif endfunction function ipmask($ipaddress1, $ipaddress2) Dim $bit if instr($ipaddress1,'.') or instr($ipaddress2,'.') or len($ipaddress1)<>32 or len($ipaddress2)<>32 exit 87 endif $ipmask='' for $bit=1 to 32 $ipmask=$ipmask+(val(substr($ipaddress1,$bit,1)) & val(substr($ipaddress2,$bit,1))) next endfunction function BinaryIP($IP) DIM $item, $bitsize, $octet $bitsize = 128 $ip = split($IP,".") select case UBOUND($ip) <> 3 $BinaryIP = 0 exit(87) case 1 for each $octet in $ip if VAL($octet) <0 OR VAL($octet) > 255 $BinaryIP = 0 exit(87) endif while $bitsize > 0 if val($octet) & $bitsize $Binary = $Binary + "1" else $Binary = $Binary + "0" endif $bitsize = $bitsize / 2 loop $binaryIP = $binaryIP + "$binary" $bitsize = 128 $binary = "" next endselect exit(0) endfunction
|
Top
|
|
|
|
#95055 - 2002-11-02 11:16 PM
Re: Trigger Your Logon Script - WMI
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Heres a screenie of Task Manager after running this event monitor overnight. As you can see, there is very little CPU utilization going on. In fact, moving the mouse causes more CPU time than this script, as evidenced by the little peak at the end of the graph. Well, the picture previews OK, but doesnt' show. Here's the link:
http://www.geocities.com/gk_zone/task_scrnshot.JPG [ 02. November 2002, 23:17: Message edited by: Chris S. ]
|
Top
|
|
|
|
#95056 - 2002-11-05 05:10 PM
Re: Trigger Your Logon Script - WMI
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
|
Top
|
|
|
|
#95057 - 2002-11-05 10:46 PM
Re: Trigger Your Logon Script - WMI
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11624
Loc: CA
|
Thanks again Rad. You keep adding good stuff.
Please notice the author also includes a download for the scrpt that is in VB.
http://www.desktopengineer.com/downloads/vpnraslogonhook.exe
It can be opened with WinZip, WinRar, etc... for viewing, extracting.
|
Top
|
|
|
|
#95058 - 2003-01-21 01:11 PM
Re: Trigger Your Logon Script - WMI
|
Anonymous
Anonymous
Unregistered
|
I am very happy that I found this topic. I had read the article and was already converting it to kix. This topic saves me some time.
I have two corrections on the code in this topic: 1. In function isiniprange it is assumed that variable $iprangearray is already an array; it is not. My new code:
function isiniprange($ipaddress,$ipranges) Dim $iprange, $networkid, $subnetmask, $bit $iprangearray=split($ipranges,',')
2. The script is (trying) to fire both when a VPN connection is established but also when it is disconnected. This can be changed: In $objEvents change __InstanceOperationEvent to __InstanceCreationEvent
regards Xaveer van den Berg
|
Top
|
|
|
|
#95059 - 2003-01-22 04:56 PM
Re: Trigger Your Logon Script - WMI
|
ekrasner
Fresh Scripter
Registered: 2000-12-20
Posts: 9
Loc: Federal Way, WA, USA
|
Maybe I am missing something , but how is this script started/executed on the remote PC.
|
Top
|
|
|
|
#95061 - 2003-01-22 09:09 PM
Re: Trigger Your Logon Script - WMI
|
ekrasner
Fresh Scripter
Registered: 2000-12-20
Posts: 9
Loc: Federal Way, WA, USA
|
Thanks Chris, I do have one last question though. Our users that login through VPN receive an ip adress in the range 192.168.245.1 to 192.168.245.254. How should the line $asSubnetList="xxx.xxx.xxx.xxx/255.255.255.0","xxx.xxx.xxx.xxx/255.255.255.0" read.
Thanks
|
Top
|
|
|
|
#95064 - 2003-06-14 04:19 PM
Re: Trigger Your Logon Script - WMI
|
toddo1962
Lurker
Registered: 2003-06-14
Posts: 1
|
Anyone have any idea how to monitor for a Net-Screen connection?
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(mole)
and 598 anonymous users online.
|
|
|