Page 1 of 2 12>
Topic Options
#95047 - 2002-10-31 10:43 PM Trigger Your Logon Script - WMI
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
For those of you that have a subscription to Windows .NET Magazine, there is a cool article on using WMI to monitor the connection to the network and kick off your script once the user connects via VPN/RAS etc...

Rather cool idea. Not sure if it can be converted to KiX or not though. Not sure what the overhead in memory or cpu might be.

In the November 2002 magazine on page 61

Author's email is Darwin Sanoy darwin@desktopengineer.com

Top
#95048 - 2002-10-31 10:52 PM Re: Trigger Your Logon Script - WMI
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Any chance to see this online since I don't have the subscription? At least the code itself?
_________________________
There are two types of vessels, submarines and targets.

Top
#95049 - 2002-11-01 12:04 AM Re: Trigger Your Logon Script - WMI
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Jens... I can't post the article here. I sent you a message though on the board.
Top
#95050 - 2002-11-01 03:16 PM Re: Trigger Your Logon Script - WMI
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Thanks.
_________________________
There are two types of vessels, submarines and targets.

Top
#95051 - 2002-11-01 05:32 PM Re: Trigger Your Logon Script - WMI
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
any update?
this could be good...
at least "spy" func could be there...
_________________________
!

download KiXnet

Top
#95052 - 2002-11-02 12:41 AM Re: Trigger Your Logon Script - WMI
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Doc,

I am intersted in this too.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#95053 - 2002-11-02 01:00 AM Re: Trigger Your Logon Script - WMI
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Its peaked my interest too. In fact, I'm working on a KiX conversion.
Top
#95054 - 2002-11-02 04:58 AM Re: Trigger Your Logon Script - WMI
Chris S. Offline
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. Offline
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 Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
here is the article

http://desktopengineer.com/article.php?story=20010610075500572
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#95057 - 2002-11-05 10:46 PM Re: Trigger Your Logon Script - WMI
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Thanks again Rad. You keep adding good stuff. [Wink]

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
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 Offline
Fresh Scripter

Registered: 2000-12-20
Posts: 9
Loc: Federal Way, WA, USA
Maybe I am missing something [Frown] , but how is this script started/executed on the remote PC.
Top
#95060 - 2003-01-22 06:13 PM Re: Trigger Your Logon Script - WMI
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
The script must be running on the target PC. Have it started from the Startup folder, Run key, RunOnce key, etc.

The script acts as a service/monitor to detect a new network connection.

Top
#95061 - 2003-01-22 09:09 PM Re: Trigger Your Logon Script - WMI
ekrasner Offline
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
#95062 - 2003-01-22 10:56 PM Re: Trigger Your Logon Script - WMI
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Prolly...

$asSubnetList="192.168.245.1/255.255.255.0","192.168.245.254/255.255.255.0"

...assuming that subnet mask is OK.

Top
#95063 - 2003-01-23 04:40 AM Re: Trigger Your Logon Script - WMI
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
See also TCP/IP Primer, Part I - IP Addresses
_________________________
There are two types of vessels, submarines and targets.

Top
#95064 - 2003-06-14 04:19 PM Re: Trigger Your Logon Script - WMI
toddo1962 Offline
Lurker

Registered: 2003-06-14
Posts: 1
Anyone have any idea how to monitor for a Net-Screen connection?
Top
#95065 - 2003-06-14 04:28 PM Re: Trigger Your Logon Script - WMI
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Net-Screen? Could you be a little more descriptive?
Top
#95066 - 2003-06-17 03:26 AM Re: Trigger Your Logon Script - WMI
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
And please don't hijack threads. Please read ABC's of KiXtart board etiquette and message to new forum users , start your own thread and explain your question in detail.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 2 12>


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

Who's Online
1 registered (mole) and 598 anonymous users online.
Newest Members
Raoul, Timothy, Jojo67, MaikSimon, kvn317
17875 Registered Users

Generated in 0.075 seconds in which 0.027 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