Page 1 of 1 1
Topic Options
#136026 - 2005-03-21 10:53 PM isinsubnet
dbortunk Offline
Fresh Scripter

Registered: 2001-05-18
Posts: 36
Loc: USA
I am trying to figure out the syntax for isinsubnet. I curently have

$IPAddress=@IPADDRESS0
$NetworkID='172.28.54.0'
$SubnetMask='255.255.254.0'
if IsInSubnet($IPAddress,$NetworkID,$SubnetMask)

But I need to add about 5 subnets and then write a script to check which subnet the useris in and run a script off it? What would the syntax be?

If $Answer=?

Thanks

Top
#136027 - 2005-03-21 11:48 PM Re: isinsubnet
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Did you look at the Docs for this?

Are you running KiXtart 4.21 or better?

The examples provided should help you along.

HTH,

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

Top
#136028 - 2005-03-22 12:27 AM Re: isinsubnet
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you could also use MOAN() and use it to return the subnet you are in.
would make it simpler.
_________________________
!

download KiXnet

Top
#136029 - 2005-03-22 01:03 AM Re: isinsubnet
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
also Richards, IPDecimal() can return this information too.

Code:

Call 'g:\kix\udf\IPDecimal\IPDecimal.kix'

; Get primary NIC details
$IP=EnumIPInfo(0,0)
$Mask=EnumIPInfo(0,1)

; Calculate info
$Network=IPDecimal($IP) & IPDecimal($Mask)

; Display it
? "This computer is on network: "+IPDecimal($Network)




Top
#136030 - 2005-03-22 02:09 AM Re: isinsubnet
dbortunk Offline
Fresh Scripter

Registered: 2001-05-18
Posts: 36
Loc: USA
i am running 4.21 and i read the examples but i can't figure out from the examples how I would go about having different outputs for different subnets
Top
#136031 - 2005-03-22 02:14 AM Re: isinsubnet
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lets go backwards...
what you want to do?
you want to decide by the subnet what to do, right?
or what is that script you want to fire???
_________________________
!

download KiXnet

Top
#136032 - 2005-03-22 02:16 AM Re: isinsubnet
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
with moan your situation would be simple as...
nah, I must admit. I don't know what is the problem you have.
in your above example, you have done the stuff just fine but still you seem to have some problem.

where you need to add the subnets?


Edited by Lonkero (2005-03-22 02:17 AM)
_________________________
!

download KiXnet

Top
#136033 - 2005-03-22 02:21 AM Re: isinsubnet
dbortunk Offline
Fresh Scripter

Registered: 2001-05-18
Posts: 36
Loc: USA
i need to execute an exe. But i only want it executed if the users come from either of two subnets and I have about 20 subnets
Top
#136034 - 2005-03-22 02:26 AM Re: isinsubnet
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so the if would be something like:
Code:

if IsInSubnet(@IPADDRESS0,'172.28.54.0','255.255.254.0') or IsInSubnet(@IPADDRESS0,'192.168.111.0','255.255.255.0')
;do shoot...
endif



right?
_________________________
!

download KiXnet

Top
#136035 - 2005-03-22 02:28 AM Re: isinsubnet
dbortunk Offline
Fresh Scripter

Registered: 2001-05-18
Posts: 36
Loc: USA
oh ok so that would work? I wasn't sure. But let's say that I needed to add more subnets every day, would i just continue to do he OR, or is there a more efficient way to do this
Top
#136036 - 2005-03-22 02:35 AM Re: isinsubnet
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Select
  Case 'test 1'
  Case 'test 2'
  Case etc....
EndSelect

Top
#136037 - 2005-03-22 02:39 AM Re: isinsubnet
dbortunk Offline
Fresh Scripter

Registered: 2001-05-18
Posts: 36
Loc: USA
Select
Case IsInSubnet(@IPADDRESS0,'172.28.54.0','255.255.254.0')
Case IsInSubnet (@IPADDRESS0,'192.168.111.0','255.255.255.0')
Case etc....
EndSelect

like that?

Top
#136038 - 2005-03-22 02:42 AM Re: isinsubnet
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
yep, that should work fine.
Top
#136039 - 2005-03-22 02:45 AM Re: isinsubnet
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
but, if you run the same code for each subnet that is matched, would be better with something like moan() returning the subnet you are in now. and then:
Code:

$subnets="insert","the","subnets","here","as","an","array"
if -1<ascan($subnets,$moan_sub)
;run your stuff
endif

_________________________
!

download KiXnet

Top
Page 1 of 1 1


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

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.08 seconds in which 0.05 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