Page 1 of 1 1
Topic Options
#139988 - 2005-05-19 02:20 PM IP address range mapping?
spectrum48k Offline
Lurker

Registered: 2005-05-19
Posts: 3
I'm new to scripting, I'm having problems trying to get machines via 2 IP address ranges to access a server shares. This is the script I'm using, nothing seems to be happening. Any ideas?

IF (@IPADDRESS0)= "172.16.136.*"
USE X: /Delete /persistent
USE X: "\\apps\CD-Roms"
ENDIF

IF (@IPADDRESS0)= "172.16.137.*"
USE X: /Delete /persistent
USE X: "\\apps\CD-Roms2"
ENDIF

Top
#139989 - 2005-05-19 02:57 PM Re: IP address range mapping?
Rory Daniels Offline
Getting the hang of it

Registered: 2003-02-25
Posts: 64
Loc: Bristol, UK
The @IPAddress macro brings back blank spaces in place of zeros. Try this:

Code:
If TRIM(SUBSTR(@IPADDRESS0, 1, 3)) + "." + TRIM(SUBSTR(@IPADDRESS0, 5, 3))  + "." + TRIM(SUBSTR(@IPADDRESS0, 9, 3)) = "172.16.2"
? "Matched"
Else
? "Not Matched"
Endif


Top
#139990 - 2005-05-19 02:57 PM Re: IP address range mapping?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Wildcards are not permitted and the @IPAddressx macro pads out the octets.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#139991 - 2005-05-19 03:02 PM Re: IP address range mapping?
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
there is a really nice FAQ section on this.

TCP/IP Primer, Part I - IP Addresses
TCP/IP Primer, Part II - Classless Inter-Domain Routing (CIDR)
TCP/IP Primer, Part III - IP Addresses and KiXtart

there are a numbr of UDF's to do a proper subnet check on ipaddresses, my personal favorite and one not in the FAQ.... is Richard's : IPDecimal() - IP Address to Decimal (network calc)

code example using it...

Code:

$IP=EnumIPInfo(0,0)
$Mask=EnumIPInfo(0,1)

Select
case IPDecimal(IPDecimal($IP) & IPDecimal($Mask)) = "192.168.1.0"
;you are in the 192.168.1.0 subnet

case IPDecimal(IPDecimal($IP) & IPDecimal($Mask)) = "192.168.1.2"
;you are in the 192.168.1.1 subnet

case IPDecimal(IPDecimal($IP) & IPDecimal($Mask)) = "192.168.1.3"
;you are in the 192.168.1.2 subnet

case IPDecimal(IPDecimal($IP) & IPDecimal($Mask)) = "192.168.1.4"
;you are in the 192.168.1.3 subnet
endselect


Top
#139992 - 2005-05-19 04:10 PM Re: IP address range mapping?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

my personal favorite and one not in the FAQ



Then add it. You are a mod... how hard can it be?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#139993 - 2005-05-19 04:12 PM Re: IP address range mapping?
spectrum48k Offline
Lurker

Registered: 2005-05-19
Posts: 3
I'm still not having any luck, I feel stupid. I have changed my script to the following

$ipaddress=@IPADDRESS0
$iparray[0]='172.16.136.0/24'
$iparray[1]='172.16.137.0/24'
if isiniprange($ipaddress,$iparray)
use X: "\\apps\CDRoms"
endif

My only aim is to get machines on the 172.16.136.x range and 172.16.137.x to use X: "\\apps\CDRoms" .

Top
#139994 - 2005-05-19 04:26 PM Re: IP address range mapping?
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
You may have to strip out the spaces in the @ipaddress0 macro to use that function

$ipaddress = join(split(@ipaddress0," "),"")

Top
#139995 - 2005-05-19 04:26 PM Re: IP address range mapping?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Try this. This assumes that you have one network adapter, or at least that the first adapter enumerated is the one that you are interested in.

Code:
$sMyNetwork=IPDecimal(IPDecimal(EnumIpInfo(0,0)) & IPDecimal(EnumIpInfo(0,1)))
Select
Case $sMyNetwork='172.16.136.0' OR $sMyNetwork='172.16.137.0'
"Will Map X Drive" ?
Use X: /delete /persistent
use X: "\\apps\CDRoms"
If @ERROR "ERROR: Could not map X: ["+@ERROR+"] "+@SERROR+@CRLF EndIf
Case "Default"
"Will not map X drive" ?
EndSelect

; IPDecimal Dotted Quad <-> Network number conversion
Function IPDecimal($v)
If InStr($v,".")
For Each $v In Split($v,".") $IPDecimal=$IPDecimal+Right("00"+DecToHex($v),2) Next
$IPDecimal=Val("&"+$IPDecimal)
Else
; Convert to hex and zero fill to 32 bit.
; This avoids problems caused by twos complement representation
$v=Right("00000000"+DecToHex($v),8)
While $v
$IPDecimal=$IPDecimal+"."+Execute("Exit &"+Left($v,2))
$v=SubStr($v,3)
Loop
$IPDecimal=SubStr($IPDecimal,2)
EndIf
Exit 0
EndFunction


Top
#139996 - 2005-05-19 04:44 PM Re: IP address range mapping?
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Quote:

Quote:

my personal favorite and one not in the FAQ



Then add it. You are a mod... how hard can it be?




hard. Since i am not a mod on the FAQ forum

Top
#139997 - 2005-05-19 05:07 PM Re: IP address range mapping?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

hard. Since i am not a mod on the FAQ forum



Talk to jooel then. All mods had full access before the last upgrade.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#139998 - 2005-05-19 05:23 PM Re: IP address range mapping?
spectrum48k Offline
Lurker

Registered: 2005-05-19
Posts: 3
Thanks Guys, all your help has resolved the problem
Top
#139999 - 2005-05-19 05:30 PM Re: IP address range mapping?
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Richard...

Shouldn't this...
Code:
 Case $sMyNetwork='172.16.136.0' OR $sMyNetwork='172.16.136.0' 


Be this...
Code:
 Case $sMyNetwork='172.16.136.0' OR $sMyNetwork='172.16.137.0' 


Top
#140000 - 2005-05-20 09:36 AM Re: IP address range mapping?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quote:

Richard...

Shouldn't this...
Code:
--------------------------------------------------------------------------------

Case $sMyNetwork='172.16.136.0' OR $sMyNetwork='172.16.136.0'

--------------------------------------------------------------------------------

Be this...
Code:
--------------------------------------------------------------------------------

Case $sMyNetwork='172.16.136.0' OR $sMyNetwork='172.16.137.0'





Yup. There were a couple of typos in there - should be ok now.

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 342 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.132 seconds in which 0.096 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