Page 1 of 1 1
Topic Options
#203086 - 2011-09-15 02:33 PM new to kixtart - need help with location/subnet based actions
tonymorin Offline
Just in Town

Registered: 2011-08-31
Posts: 3
Loc: indiana
hey guys im really new to kixtart and im having trouble finding a good why to filter out shourtcuts by ip or subnet.
Problem: i have main facility in indiana that needs MSDS shortcut that only pertains to that facility. one more facility in north Carolina that needs another different MSDS shortcut icon to only display on the users desktops. both file systems and icons are hosted local in indiana server.

I have been trying some

@ipaddress

trying to using cidr 10.0.3.0/24

I think it might be out of the range of my skill as of right now.
please if anyone can help
Thanks Tony


Edited by Mart (2011-09-15 02:49 PM)
Edit Reason: Updated title to state the issue.

Top
#203087 - 2011-09-15 02:59 PM Re: new to kixtart - need help with location/subnet based actions [Re: tonymorin]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You can take several routes to get what you want.

  • If the systems have a unique site identification in their name you could get a substring of the @WKSTA macro and act upon the outcome.
  • You could also use (a part of) @IPADDRESS0 and create the shortcuts if it matches a certain value. Beware the @IPADDRESS macro always returns three positions for each octet. It will return 192.168. 1. 1 if your IP is 192.168.1.1 (note the spaces in octet 3 and 4).
  • If they are in different sites in AD you can use the @SITE macro.

It all depends on your setup.

Some examples:
 Code:
Select
	Case Left(@IPADDRESS0, 11) = "192.168.  1"
		;do stuff
	Case Left(@IPADDRESS0, 11) = "192.168.  2"
		;do other stuff
EndSelect

or
 Code:
Select
	Case @SITE = "AAA"
		;do stuff
	Case @SITE = "BBB"
		;do other stuff
EndSelect

or
 Code:
Select
	Case InStr(@WKSTA, "SITEA")
		;do stuff
	Case InStr(@WKSTA, "SITEB")
		;do other stuff
EndSelect
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#203088 - 2011-09-15 03:55 PM Re: new to kixtart - need help with location/subnet based actions [Re: tonymorin]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
@IPADDRESS is text based and a messy way of mananging IP info..

This will convert the IP address string to a normal IP address without extra spaces.
 Code:
$MyIP = Join(Split(@IPADDRESS, ' '), '')
Now that you have an IP address, you can use one of several UDFs that can perform CIDR calculations and tell you which subnet that IP address belongs to. Once you know which subnet you are a member of, you can easily apply the "one or many" logic to create the MSDS shortcuts.

Here's some PseudoCode to give you an idea of how it works. First, you need a table of network subnet ranges in an array.
 Code:
$SiteSubnets = '192.168.0.0/22','192.168.4.0/23','192.168.6.0/23'
Note that this array aggregates the individual subnets at a site - the first has networks 0-3, the second 4-5, and the third 6-7. We aren't interested so much in the subnet but the SITE where the subnet exists! Here's some basic working code. You'll need the IsInSubnet UDF, either from KORG or my library.
 Code:
Call '\KixLib\IsInSubnet.udf'

; define the subnets at each site
$aSiteSubnets = '192.168.0.0/22','192.168.4.0/23','192.168.6.0/23'

; Define each of the URL strings
$aURLs = 'URL1', 'URL2', 'URL3'

; Define which URLs are assigned to each site. In this example, site 0 gets URL0, Site 1 gets URL 0 and 1, etc..
$aSiteURLs = '0', '0,1', '2'

; Eliminate spaces in the IP macro
$MyIP = Join(Split(@IPADDRESS0, ' '), '')



; Use a UDF to determine which subnet the current IP resides in.
$aMySite = isinsubnet($MyIP,$aSiteSubnets)


; If no error, get the Site ID
If Not @ERROR


 'My IP: ' $MyIP ?		; debug message

  $Site = AScan($aMySite, 1)

 'My Site ID: ' $Site ?		; debug message
 'URLs: ' $aSiteURLs[$Site] ?	; debug message

  $URL_List = Split($aSiteURLs[$Site], ',')
  For Each $Url in $URL_List
    $aURLs[$Url] ' is being defined' ?
    ; Use a UDF to create the shortcut to the URL
  Next
Else

  'IP is not in any Site network!' ?

EndIf
By using the UDF and sticking with CIDR calculations, you can aggregate subnets by site without lots of "InStr()" calls to test for each individual subnet.

BTW - Welcome to KORG!

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#203090 - 2011-09-15 06:03 PM Re: new to kixtart - need help with location/subnet based actions [Re: Glenn Barnas]
tonymorin Offline
Just in Town

Registered: 2011-08-31
Posts: 3
Loc: indiana
wow thx for the fast solutions guys. as i have been thinking about it. we do have defined ip ranges . so could i say some like...

if 10.0.5.0>
then MSDS shourtcut A
Eles
do MSDS shourtcut b


any thoughts?
thx again guys \:\)

Top
#203091 - 2011-09-15 08:26 PM Re: new to kixtart - need help with location/subnet based actions [Re: tonymorin]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
There are a ton of ways to do it, as they pointed out above...this would probably work...but not as fail safe as glenn's suggestion.

 Code:
If Left(Join(Split(@IPADDRESS0, " "),""),6) = "10.0.5"
   MSDS A
Else
   MSDS B
Endif

Top
#203094 - 2011-09-16 03:12 PM Re: new to kixtart - need help with location/subnet based actions [Re: ShaneEP]
tonymorin Offline
Just in Town

Registered: 2011-08-31
Posts: 3
Loc: indiana
i dont think i got this right....sorry...im new to this..CLS
here is just a small amount of what im putting in..??




DIM $CommonOF
DIM $CommonSH
DIM $dev

$CommonOF = "True"
$CommonSH = "False"

If Left(Join(Split(@IPADDRESS0, " "),""),6) = "10.0.5"
copy "F:\IT\Shortcuts\MSDS-Mount Airy.lnk" "C:\documents and settings\all users\desktop"
Else
copy "F:\IT\Shortcuts\MSDS-Fort Wayne.lnk" "C:\documents and settings\all users\desktop"
Endif

IF @USERID = "bob" or @USERID="bob2" or @USERID="bob3" or @USERID="bob4" or @USERID="bob5" or @USERID="bob6"
USE f: /DELETE
USE i: /DELETE
USE n: /DELETE
USE o: /DELETE
USE p: /DELETE
USE q: /DELETE
USE r: /DELETE
USE s: /DELETE
USE t: /DELETE
USE u: /DELETE
USE v: /DELETE


Edited by tonymorin (2011-09-16 04:38 PM)

Top
#203095 - 2011-09-16 03:15 PM Re: new to kixtart - need help with location/subnet based actions [Re: ShaneEP]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
Using the IsInSubnet method allows you to write and validate the script ONCE, and then the only changes are to the data - subnets, URLs, and Subnet/URL map. Ideally, these three items could be read from an INI file so the code never again needs to be changed.

When you mess with IP addresses as strings and do InStr() tests, you need to keep changing your code to accommodate changes to your network.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#203096 - 2011-09-16 03:21 PM Re: new to kixtart - need help with location/subnet based actions [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
Apparently, you've got data sprinkled throughout your script! Ahhhgh! ;\)

Unless your company has 5 or fewer people, having user-specific settings in your login script is a maintenance nightmare. AD Groups, my friend, are your BEST friend.
 Code:
If InGroup(groupname) do stuff... EndIf
We usually create an OU called AccessControls, and create "AC-sharename" groups. These groups control modify access to various folders. Adding "-RO" to the sharename indicates READ access only. It's easy to maintain - and folders have at most 5 permissions set - Admins, System, Owner, AC-share, and (optionally) AC-share-RO. Granting or revoking permission requires only one group edit.

Also, take a look at the UDFs to create shortcuts. Copying a .lnk file may not have the same logical reference on the target computer. Creating the link fresh via the UDF will insure that the .LNK points to the right target, whether local or remote.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

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 323 anonymous users online.
Newest Members
Audio, Hoschi, Comet, rrosell, PatrickPinto
17880 Registered Users

Generated in 0.059 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

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