Page 1 of 1 1
Topic Options
#196571 - 2009-11-03 11:07 PM Having trouble with 2 dim type of array? parallel type?
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Hello kix gurus, working on another project at work but I cannot get this array correct.
What I want to do is I have 2 arrays one for the IP address and one for the MAC address of the PCs I am going to wake-up on command. I know I know some of you guys want me to use WMI but I have tried that and it is very slow compare to this shell command. So I am going with this hybrid setup.

Okay my issue is I not sure how I can move thru the 2 lists of arrays
and take IP and MAC and then move to the next (parallel array type).
I know what I am doing below is not correct but I dont know how to
work this I believe you call it a parallel array setup in 2 dimensions corrrect guys? Thanks if you can give me some guidance I would buy you a beer or tickets to walt disney world....okay I cant do that but it sounds nice huh? ahha Thank guys


 Code:


Dim $IP_8TH
Dim $MAC_8TH

 $IP_8TH = "192.168.2.85", 
$MAC_8TH = "0021851165F4",

;8th Street (ip for routing)
sleep 5
For Each $IP in $IP_4th
    For Each $MAC in $MAC_4TH
 	Shell "cmd.exe /c wol.exe $IP $MAC"
    Next
Next



_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#196572 - 2009-11-03 11:19 PM Re: Having trouble with 2 dim type of array? parallel type? [Re: itdaddy]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Your question is confusing so if this is not what you want, can you rephrase it?

This is using two different arrays.
 Code:
$ips="1.1.1.1","2.2.2.2","3.3.3.3"
$macs="abcde","efghi","jklmn"
for $i=0 to ubound($ips)
  ? $ips[$i]
  ? $macs[$i]
next


You could also use a multidimensional array, but I think the method above is easier.


Top
#196573 - 2009-11-03 11:36 PM Re: Having trouble with 2 dim type of array? parallel type? [Re: Allen]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Allen
hahah yeah it shows that I was confused. hey thanks for your time
I really appreciate your help. I will post my program for others to see
thank you will give it a try;)
cheers mate!
-itdaddy
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#196574 - 2009-11-04 08:58 AM Re: Having trouble with 2 dim type of array? parallel type? [Re: itdaddy]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
For your application you don't actually need two arrays at all.
 Code:
$IPMAC_8TH="192.168.2.85 0021851165F4",
           "192.168.2.92 002144CB2F43",
           "192.168.2.168 002168D92EA8"
              
For Each $IPMAC in $IPMAC_8th
	Shell "cmd.exe /c wol.exe "+$IPMAC
Next

Top
#196575 - 2009-11-04 12:29 PM Re: Having trouble with 2 dim type of array? parallel type? [Re: Richard H.]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
That's a great catch. I was going to point out that having two arrays means you are more likely to get them out of sync. Having them in the same array as Richard suggested alleviates that problem.
Top
#196577 - 2009-11-04 03:58 PM Re: Having trouble with 2 dim type of array? parallel type? [Re: BradV]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
HAHAH richard you are right hahah
what a nooob I am haaha yeah really I dont ahha
thanks but it was cool to see the other way. but hey thank you
;\)

super. yeah I am making a program that connects to a flash button
on a webpage like consle that when clicked turns all the machines
on with oneclick cool huh and I have another program I made that checks
all machines (with AD array input of all pcs in AD) if they are up and if not I click the button and bam they come on! sweeet huh..
will post it here when I am done ;\) thanks for that insight.
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#196578 - 2009-11-04 04:05 PM Re: Having trouble with 2 dim type of array? parallel type? [Re: itdaddy]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Hey guys
I have a stupid question say I want to make a function
so I can reuse it vs makint iterations of each. I have not done
a function in kix to pass an array is this how I do it?

 Code:
 

$IPMAC_8TH = "192.168.1.45 abcdefg", "192.168.1.56 abcdefg"....
wol_Yes_IP($IPMAC_8TH)


function wol_Yes_IP($IPMAC)

 For each $IPMAC in $IPMAC_8TH
       Shell "cmd.exe /c wol.exe $IPMAC"
 Next

EndFunctioin



_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#196579 - 2009-11-04 04:12 PM Re: Having trouble with 2 dim type of array? parallel type? [Re: itdaddy]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
A small modification to your function....

 Code:
$IPMAC_8TH = "192.168.1.45 abcdefg", "192.168.1.56 abcdefg"....

For Each $IPMAC in $IPMAC_8TH
	$rc = wol_Yes_IP($IPMAC)
Next

Function wol_Yes_IP($IPMAC)
	Shell "cmd.exe /c wol.exe $IPMAC"
EndFunction
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#196580 - 2009-11-04 04:48 PM Re: Having trouble with 2 dim type of array? parallel type? [Re: Mart]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
Hey thanks mart
for that '$rc ='. what does that do again something like clean the function call up??? or something like that?
super ;))
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#196581 - 2009-11-04 04:53 PM Re: Having trouble with 2 dim type of array? parallel type? [Re: itdaddy]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
$rc will catch any return code the function sends back tro your script.
If you do not use Something like $rc (or $1, $2 or whatever, you could use any variable name you like) you could get alls sorts of unwanted screen output.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#196582 - 2009-11-04 05:16 PM Re: Having trouble with 2 dim type of array? parallel type? [Re: Mart]
itdaddy Offline
Starting to like KiXtart

Registered: 2006-12-19
Posts: 145
Loc: Wisconsin
you the man mart! thanks big guy!
here she is in a nutshell.
 Code:

;**********************************
; Begin WOL.KIX
;**********************************
Break On
;*********************************
; Declare/Define Arrays Section
;*********************************
Dim $IPMAC_4TH
Dim $IPMAC_8TH
Dim $IPMAC_PLOVER
Dim $IPMAC_POINT

;4th avenue IP ONLY (no routing needed)
$IPMAC_4TH = "192.168.1.45", "192.168.1.56"





;8th Street
$IPMAC_8TH = "192.168.1.45 abcdefg", "192.168.1.56 abcdefg"





;Plover
$IPMAC_PLOVER = "192.168.1.45 abcdefg", "192.168.1.56 abcdefg"






;Point
$IPMAC_POINT = "192.168.1.45 abcdefg", "192.168.1.56 abcdefg"


;*********************************
;Wake-Up LAN Main
;*********************************

;4th avenue
For Each $IPMAC in $IPMAC_4TH
	$rc = wol_Master($IPMAC)
Next

;8th street
sleep 5
For Each $IPMAC in $IPMAC_8TH
	$rc = wol_Master($IPMAC)
Next

;plover
sleep 5
For Each $IPMAC in $IPMAC_PLOVER
	$rc = wol_Master($IPMAC)
Next

;point
sleep 5
For Each $IPMAC in $IPMAC_POINT
	$rc = wol_Master($IPMAC)
Next

;**********************************
; WOL function Master
;**********************************

Function wol_Master($IPMAC)
	Shell "cmd.exe /c wol.exe $IPMAC"
EndFunction


;**********************************
; End of WOL.KIX
;**********************************





Edited by itdaddy (2009-11-04 05:19 PM)
_________________________
Robert
A+, CCNA, MCP
Network Admin
Credit Union Wisconsin

Top
#196586 - 2009-11-05 11:57 AM Re: Having trouble with 2 dim type of array? parallel type? [Re: itdaddy]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
Hi Robert,

The only thing I would suggest is put the "data" in an ini file. I believe Glenn brought that up earlier. It leaves the logic in your kix script, but moves the data out of it. That way, as your topology changes, your script doesn't have to, just the ini file. In fact, you could loop through the ini file and get rid of the separate sections for each street.

Top
#196587 - 2009-11-05 02:06 PM Re: Having trouble with 2 dim type of array? parallel type? [Re: BradV]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
I'm SO tired of bringing that up, actually, so THANKS for that, Brad! ;\)

"DcAoTdAe" is BAD!

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

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 611 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.163 seconds in which 0.116 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