Page 1 of 1 1
Topic Options
#171577 - 2006-12-15 06:11 PM Network (and wireless) disconnector
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL

This initially started as a way of blocking users from connecting to hotspots.

user will probably need local admin, or you could run this under system acct, but that will not have access to the VPN group membership.

Code:
;
;  Script will not run if user is member of VPN group
;  Disconnection is issued as DHCP release
;  Script will provide details for network disconnections to "IT_Staff"
;  All networks that are NOT in DHCP 192.92.0.0 will disconnected
;  All connections, wired and wireless, are subject to disconnection
;

break on

if not ingroup('VPN')

;   **********  To detect an existing connection prior to this script's execution
$objWMIService = GetObject("winmgmts:\\.\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each $objItem in $colItems
	$arrIPAddresses = $objItem.IPAddress
	For Each $strAddress in $arrIPAddresses
		if left($strAddress,6)<>'0.0.0.' and left($strAddress,6)<>'192.92'
			$nul = $objItem.ReleaseDHCPLease()
			$err = @serror + ': Releasing '
			if ingroup("IT_Staff")
				$nul = messagebox($objItem.Description+@crlf+$strAddress+@crlf+$err,'Network Connection Denied',0) 
			endif
			$nul = messagebox("You have attempted to connect to an unauthorized network."+@crlf+"Please contact IT Helpdesk at 866-123-4567 for assistance",'Network Connection Denied',0) 
        EndIf
    Next
Next


;   **********  To detect new connection attempts since this script's execution
$Query = "SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE TargetInstance ISA 'Win32_NetworkAdapterConfiguration' and targetInstance.IPEnabled = true"
$objEvents = GetObject("winmgmts:\\.\root\cimv2").ExecNotificationQuery($query)
While 1
	$objConnectEvent = $objEvents.nextevent
	$aIPAddress = $objConnectEvent.TargetInstance.IPAddress
	For Each $sAddress in $aIPAddress
		if left($sAddress,6)<>'0.0.0.' and left($sAddress,6)<>'192.92'
			$release = $objConnectEvent.TargetInstance.ReleaseDHCPLease()
			$err = @serror + ': Releasing '
			if ingroup("IT_Staff")
				$nul = messagebox($objConnectEvent.TargetInstance.Description+@crlf+$sAddress+@crlf+$err,'Network Connection Denied',0) 
			endif
			$nul = messagebox("You have attempted to connect to an unauthorized network."+@crlf+"Please contact IT Helpdesk at 866-123-4567 for assistance",'Wireless Network Connection Denied',0) 
		endif
	Next
loop

endif
 
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#171673 - 2006-12-18 04:39 PM Re: Network (and wireless) disconnector [Re: Radimus]
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
Nice \:\)

So how is this executed?
_________________________
The tart is out there

Top
#171677 - 2006-12-18 06:09 PM Re: Network (and wireless) disconnector [Re: masken]
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
run it with wkix at logon...

I wrapped it with iexpress and call it from HKLM\...\run

the second part loops and checks for new connections every 5 seconds
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 1 of 1 1


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

Who's Online
0 registered and 259 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.052 seconds in which 0.024 seconds were spent on a total of 14 queries. Zlib compression enabled.

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