anthonyalderson
(Getting the hang of it)
2003-04-24 02:23 PM
IsInIPRange Function

hi everyone, i'm new to kixtart and i'd like to ask a few questions if anyone would be so kind to answer, i've recently been creating a script to define default printers across a network of 18 remote centres, thing is i'm new to all this and the function i'd like to use i dont understand, the function is the isiniprange one, i dont understand how the dependencies work and what i need to do to create the script so that it'll check the local machines ip address against that defined in the array of said function, anyway thats quite a lot to read so i'll leave it with you guys if you dont mind, thanks for any help you might be able to give me guys,

Anth


LonkeroAdministrator
(KiX Master Guru)
2003-04-24 02:32 PM
Re: IsInIPRange Function

heh, don't worry...
I've been checking and reading it many times and have not understood it by this date! [Big Grin]


Sealeopard
(KiX Master)
2003-04-24 03:02 PM
Re: IsInIPRange Function

That's a first, Jooel admitting that he doesn't get a UDF. Maybe we should convert it into the next KiXGolf challenge? Make IsInIPRange smaller and remove the dependencies? [Big Grin]

Anyway, I think the UDF is straight-forward. However, I also wrote it [Wink]

First of all, please read TCP/IP Primer, Part I - IP Addresses to refresh your TCP/IP network knowledge.

Secondly, you'll need to include IsInIPRange and it's two dependiencies in your script as e.g. described in How to use UDFs .

Finally, you feed the IP address and an array of networkIDs/subnets into the UDF and you will get a return statement indicating whether the IP address is part of the network. Please implement the example provided in the function header to see how it works.


anthonyalderson
(Getting the hang of it)
2003-04-25 11:10 AM
Re: IsInIPRange Function

thanks guys, you've given me a bit of insight into kix, and i feel a little more confident now, and now i'm just gonna have to play about with my script and include the necessary functions (of which i wasnt sure i had to do before), so many thanks guys and if i ever see you out sometime just tap me on the shoulder and i'll buy you a drink.

Anth


LonkeroAdministrator
(KiX Master Guru)
2003-04-25 11:26 AM
Re: IsInIPRange Function

mm...
what drink?
scotch?


anthonyalderson
(Getting the hang of it)
2003-04-26 12:12 AM
Re: IsInIPRange Function

yeah will a double do?

LonkeroAdministrator
(KiX Master Guru)
2003-04-26 12:13 AM
Re: IsInIPRange Function

that sounds nice...

even almost worth to travel to england for just that drink [Wink]


Sealeopard
(KiX Master)
2003-04-25 02:45 PM
Re: IsInIPRange Function

No rocks for me, please [Smile]

anthonyalderson
(Getting the hang of it)
2003-04-25 03:08 PM
Re: IsInIPRange Function

okay guys i think i'm getting there, but could you have a look at this and tell me where i'm going wrong please, oh and dont worry about ice lads, i'll buy you a bottle of glenfiddich each for helping me out,

; DEFAULTPRINTER
; To retrieve local machines IP address and cross reference it against a set of defined subnets
;
; AUTHOR Anthony Alderson

CALL "binaryip.kix"
CALL "ipmask.kix"
CALL "isinsubnet.kix"
CALL "isiniprange.kix"

$ipaddress='@IPADDRESS0'
$iparray[0]='192.168. 12. 0/255.255.255. 0' ;ragworth

IF $ipaddress=$iparray[0]
? "you stink"
sleep 3
ELSE
? "guess you dont stink after all"
sleep 3
ENDIF


ShawnAdministrator
(KiX Supporter)
2003-04-25 03:18 PM
Re: IsInIPRange Function

drinks ! oh boy, can I help too ?

LonkeroAdministrator
(KiX Master Guru)
2003-04-25 03:19 PM
Re: IsInIPRange Function

well, from the function example I can tell:


; DEFAULTPRINTER
; To retrieve local machines IP address and cross reference it against a set of defined subnets
;
; AUTHOR Anthony Alderson
;modified 25.4.2003 by Lonk
 
CALL "isiniprange.kix"
;and it's requirements:
CALL "binaryip.kix"
CALL "ipmask.kix"
CALL "isinsubnet.kix"
 
if isiniprange('@IPADDRESS0','192.168. 12. 0/255.255.255. 0';ragworth
"you stink"
ELSE
"guess you dont stink after all"
ENDIF
sleep 3



[ 25. April 2003, 15:28: Message edited by: Lonkero ]


Les
(KiX Master)
2003-04-25 03:25 PM
Re: IsInIPRange Function

The CALLs to the UDFs are too optimistic. You should also combine them into one file and use a UDF extension.

CALL "binaryip.kix"
CALL "ipmask.kix"
CALL "isinsubnet.kix"
CALL "isiniprange.kix"

Could become:
CALL @ScriptDir+'\IPLibrary.udf'


Sealeopard
(KiX Master)
2003-04-25 03:28 PM
Re: IsInIPRange Function

Hmm, there's a reason why there's an example part in the function header [Smile]

And I believe it should also handle the spaces in the IP addresses, too.


JochenAdministrator
(KiX Supporter)
2003-04-25 03:30 PM
Re: IsInIPRange Function

BOOOOZE !!!! [Eek!] [Eek!] [Eek!]

whats your problems ? [Big Grin]


LonkeroAdministrator
(KiX Master Guru)
2003-04-25 03:33 PM
Re: IsInIPRange Function

sorry Jpo, I got here first [Razz]

anthonyalderson
(Getting the hang of it)
2003-04-25 03:34 PM
Re: IsInIPRange Function

thanks lonkero, i've tried your revised script but it doesnt work at present, simply telling me it expects an expression in line 13 which is the 'if isiniprange.......'

not sure why its doing as i'm inexperienced at this but shouldnt i split up my @ipaddress0 and the range i'm looking in somehow. oh and i've drunk half the bottle lads so we need quicker responses lol, but cheers all of you anyway for helping me out,
Anth


anthonyalderson
(Getting the hang of it)
2003-04-25 03:37 PM
Re: IsInIPRange Function

yeah jens i saw that, so if i try it using your example and calling in the outside udf's at the start you think i could tweak it to set the printer up, oh and by the way you're so bloody vague with your replies i can hardly see them on screen lol,

cheers,

Anth


LonkeroAdministrator
(KiX Master Guru)
2003-04-25 03:40 PM
Re: IsInIPRange Function

anthony, make sure the calling lines are proper.
I might suggest you do:
code:
CALL @scriptdir+"\isiniprange.kix"
;and it's requirements:
CALL @scriptdir+"\binaryip.kix"
CALL @scriptdir+"\ipmask.kix"
CALL @scriptdir+"\isinsubnet.kix"

in this situation if script run during logon, they have to be in the same dir as logonscript.

the expression error suggests right that, the load has failed.


LonkeroAdministrator
(KiX Master Guru)
2003-04-25 03:41 PM
Re: IsInIPRange Function

yeah, the b00ze...
no worries man, I have vodka waiting at home [Big Grin]


Sealeopard
(KiX Master)
2003-04-25 03:42 PM
Re: IsInIPRange Function

Since you're only checking for a single subnet, the IsInSubnet() should suffice. IsInIPRage is for cases where you have to check for one of many subnets. We e.g. have three separate subnets for VPN connections.
code:
$ipaddress=@IPADDRESS0
$subnet='192.168.12.0/255.255.255.0'
; or
; $subnet='192.168.12.0/24'
if IsInSubnet($ipaddress,$subnet)
; is in subnet
else
; sorry
endif



[ 25. April 2003, 15:42: Message edited by: sealeopard ]


anthonyalderson
(Getting the hang of it)
2003-04-25 04:05 PM
Re: IsInIPRange Function

well lads its a success, the damn thing works now and i couldnt have done it without any of you, so many many thanks guys (and girls!) and i'd just like to say what a wonderful resource this bulletin board is, so where do i mail the glenfiddich then??

Cheers Everyone,

Anth


LonkeroAdministrator
(KiX Master Guru)
2003-04-25 04:07 PM
Re: IsInIPRange Function

Jooel Nieminen
tangokuja 4 b 46
40520 JKL
Suomi Finland

[Big Grin]
what was the pending part?


anthonyalderson
(Getting the hang of it)
2003-04-25 05:11 PM
Re: IsInIPRange Function

its in the post jooel, and not sure what you mean by the pending part? but just to let you know with all your help guys i've managed to edit the script to work across 18 different centres now, so big well done to everyone and dont worry i've put you all in under the author(s). thanks everyone,

LonkeroAdministrator
(KiX Master Guru)
2003-04-25 05:23 PM
Re: IsInIPRange Function

pending...
I ment what was the last piece you added there to make it work...

just for future references.


anthonyalderson
(Getting the hang of it)
2003-04-27 04:57 PM
Re: IsInIPRange Function

oh sorry jooel, i'll post the full code monday morning and let you have a look, thanks for all your help though, i think all i was doing wrong was just not calling the dependencies in correctly (by not including the full path) other than that i simply used your approach and then created a select-case to fill in 18 centres worth, the codes only been tested locally but i'll be testing it this week in each of our centres and i'll let you all know how it goes.

Anth

"He who talks too much and knows very little"


Sealeopard
(KiX Master)
2003-04-27 06:42 PM
Re: IsInIPRange Function

Put the list of centers into an .INI file and read it fromt here. Then you can cycle through them and you can easyly adapt your code. example:
code:
; .INI file
[192.168.0.0]
Call=function1
[192.168.1.0]
Call=function2

code:
$networkids=split(readprofilestring('file.ini','','')
$id=0
$done=0
do
if isinsubnet(@IPADDRESS0,$networkids[$id]
$function=readprofilestring('file.ini,$networkids[$id],'Call')
$rc=execute('$rc='+$function+'()')
$done=1
endif
until $id>ubound($networkids) or $done
if not $done
; unidentified network
endif



anthonyalderson
(Getting the hang of it)
2003-04-28 10:37 AM
Re: IsInIPRange Function

thanks for the hint jens, i think i will do that in future but for now i'm happy to leave it as is, the code runs fine and takes but a second or two to complete its cycle, but i will do that in a future script, maybe when i begin to revise this one, but thanks again jens, and thanks for all your help with the code itself,

Anth