#147212 - 2005-09-06 05:48 PM
Works but not works ?!ス#?!
|
JazzM
Getting the hang of it
Registered: 2004-04-23
Posts: 91
|
Trying to get the first MAC for an IP. The code below will print the first MAC as i want it, but also en error: unexpected command! - pointing on the last empty line of the script. What Im donig wrong?
$IP = "192.168.10.10"
$MACz = WMIQuery("MACAddress","Win32_NetworkAdapter",$IP)
For Each $MAC in $MACz If $MAC>0 AND NOT InStr($MAC,"50:50:54")
$PMAC = $MAC[0]
? $PMAC
EndIf
Function WMIQuery($sWhat, $sFrom, Optional $sComputer, Optional $sWhere, Optional $x, Optional $root, Optional $sUserID, Optional $sUserPW) Dim $sQuery, $objEnum, $sValue, $TMP, $SystemSet, $, $objInstance, $objLocator
$sComputer = Trim(Join(Split($sComputer,'\'),'')) If NOT $sComputer OR $sComputer = @wksta $sComputer = '.' EndIf If NOT $root $root = '\root\cimv2' EndIf $sQuery = 'Select ' + $sWhat + ' From '+ $sFrom If $sWhere AND $x $sQuery = $sQuery+" Where "+$sWhere+" = '"+$x+"'" EndIf If $sUserID AND $sUserPW AND $sComputer <> '.' $objLocator = CreateObject('WbemScripting.SWbemLocator') If @ERROR OR NOT $objLocator Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf $SystemSet = $objLocator.ConnectServer($sComputer, $root, $sUserID, $sUserPW) If @ERROR OR NOT $SystemSet Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf $SystemSet.Security_.ImpersonationLevel = 3 Else $SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"+$sComputer+$root) If @ERROR OR NOT $SystemSet Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf EndIf $objEnum = $SystemSet.ExecQuery($sQuery) If @ERROR OR NOT $objEnum Exit Val("&"+Right(DecToHex(@ERROR),4)) EndIf For Each $objInstance In $objEnum $=Execute(Chr(36) + 'sValue = ' + Chr(36) + 'objInstance.' + $sWhat) If VarType($sValue) & 8192 $tmp = $tmp +'|' + Join($sValue,'|') Else $tmp = $tmp +'|' + $sValue EndIf Next $WMIQuery = Split(SubStr($tmp,2),'|') Exit Val("&"+Right(DecToHex(@ERROR),4)) EndFunction
_________________________
I will always look out from behind these eyes...
|
|
Top
|
|
|
|
#147217 - 2005-09-06 06:09 PM
Re: Works but not works ?!ス#?!
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
|
Top
|
|
|
|
#147218 - 2005-09-06 06:16 PM
Re: Works but not works ?!ス#?!
|
JazzM
Getting the hang of it
Registered: 2004-04-23
Posts: 91
|
NOOO Jochen ...then it will print ALL MACz for found NIC interfaces... I just want the first one... the mac in first line ... what 2 do?
_________________________
I will always look out from behind these eyes...
|
|
Top
|
|
|
|
#147226 - 2005-09-06 11:36 PM
Re: Works but not works ?!ス#?!
|
maciep
Korg Regular
   
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
hmmm sounds like he wants the first mac that passes his condition. But the condition to me seems a bit repetitive. I'm thinking something like this.
Note - see how i'm using the code tags 
Code:
$PMAC="" $MACz = WMIQuery("MACAddress","Win32_NetworkAdapter",$IP) For Each $MAC in $MACz If Not $PMAC and NOT InStr($MAC,"50:50:54") $PMAC = $MAC EndIf Next ? $PMAC
|
|
Top
|
|
|
|
#147228 - 2005-09-07 04:14 AM
Re: Works but not works ?!ス#?!
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Original Code Code:
FOR EACH $mac IN $macz IF $mac>0 AND NOT InStr($mac,"50:50:54") $pmac = $mac[0] ? $pmac ENDIF
;($begin) ; ; tue 06-sep-2005 18:53:58 (kix 4.20 vs 4.00e) ; ;Informative KIXSTRIP: input=12 output=12 skip=0 ; ;Warning KIXSTRIP: 1 error in block structure. missing statement(s). ; - do:until [0:0] ; -ERROR- - for|each:in|to:step|next [1|1:1|0:0|0] ; - function:endfunction [0:0] ; - if:else:endif [1:0:1] ; - select:case:endselect [0:0:0] ; - while:loop [0:0] ;Warning KIXSTRIP: some lines contains errors or possible errors. ;Informative KIXSTRIP: 2 block_structures found. ;Informative KIXSTRIP: no UDF's found. ;Informative KIXSTRIP: no labels found. ;Summary KIXSTRIP: BREAK CALL DEBUG DISPLAY ENDFUNCTION EXECUTE EXIT FUNCTION GET GETS GOSUB GOTO OLExxx PLAY QUIT RETURN RUN SHELL SLEEP THEN USE ; ;($end) ;($begin) ; ; ;($end)
Changed and updated: Code:
FOR EACH $mac IN $macz IF $mac>0 AND NOT InStr($mac,"50:50:54") $pmac = $mac[0] ? $pmac ENDIF NEXT
;($begin) ; ; tue 06-sep-2005 18:55:35 (kix 4.20 vs 4.00e) ; ;Informative KIXSTRIP: no errors found (input=10 output=10 skip=0). ; ;Summary KIXSTRIP: block structures ; - do:until [0:0] ; - for|each:in|to:step|next [1|1:1|0:0|1] ; - function:endfunction [0:0] ; - if:else:endif [1:0:1] ; - select:case:endselect [0:0:0] ; - while:loop [0:0] ;Informative KIXSTRIP: 2 block_structures found. ;Informative KIXSTRIP: no UDF's found. ;Informative KIXSTRIP: no labels found. ;Summary KIXSTRIP: BREAK CALL DEBUG DISPLAY ENDFUNCTION EXECUTE EXIT FUNCTION GET GETS GOSUB GOTO OLExxx PLAY QUIT RETURN RUN SHELL SLEEP THEN USE ; ;($end)
HTH,
Kent
|
|
Top
|
|
|
|
#147230 - 2005-09-07 11:10 AM
Re: Works but not works ?!ス#?!
|
JazzM
Getting the hang of it
Registered: 2004-04-23
Posts: 91
|
Holly Jesus, what痴 going on here!. Lots of fingers on me. Sorry but I知 not that intelligence as u are.
Quote:
Lonkero: you didn't.
I知 truly sorry Lonkero. Now when I know what/how, I sure will use it.
Quote:
Les: when?
I知 truly sorry Les. Now when I know such thing as "tags" exist I will use it. Hopefully I知 using it in this conversation
Quote:
Lonkero:
doesn't look like he is gonna answer...
Probably means that "he" is not online, busy on something else, gone home, eating pizza, have to go to funeral then wedding. BUT it doesn稚 necessary means that he don稚 want to answer!
Quote:
maciep :
Note - see how I知 using the code tags.
Thanks maciep :-)
Quote:
NTDOC:
Did you get this working or not?
Also... you're not that much of a noob - posting for help with a title of Works but not works ?!ス#?! is not very intuitive on what help you're looking for.
Answer: No Doc, not yet. right now I知 busy answer all fingers on me. Will get back to u when I test the codes. Plz, explain the word "noob" - my English is not that good. "Works but not works" referring to my case which I explain in beginning: that I got the output I want, but I got also an error. I知 open for any suggestions how to choose the headline for a topic :-)
___________________________________________________________________________
Now my dear friends if u don稚 mind, I will check the code and suggestion provided by you and get back to u ASAP. And many thanks for your help. U R ALL GOOD
_________________________
I will always look out from behind these eyes...
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1644 anonymous users online.
|
|
|