Ghost21 Posted August 28, 2007 Posted August 28, 2007 Trying to get the mac address from the computer and read it back into a msg box... RunWait("getmac /S " & @computernam & " /FO table /NH") then I want to get the first 17 characters = $mac and show it with a msgbox Reading the response from the run wait is what I'm having issues with... HELP PLEASE !!!
weaponx Posted August 28, 2007 Posted August 28, 2007 From http://www.autoitscript.com/forum/index.ph...hl=mac++AddressJust do $MAC = _GetMAC(1)Func _GetMAC($getmacindex = 1) $ipHandle = Run(@ComSpec & ' /c ipconfig /all', '', @SW_HIDE, 2) $macdashed = StringRegExp(StringStripWS(StdoutRead($ipHandle), 3), '([0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2})', 3) If Not @extended Then Return 0 If Not IsArray($macdashed) Then Return 0 If $getmacindex = 0 Then Return UBound($macdashed) If $getmacindex < - 1 Then Return 0 If $getmacindex > UBound($macdashed) Or $getmacindex = -1 Then $getmacindex = UBound($macdashed) $macsemicolon = StringReplace($macdashed[$getmacindex - 1], '-', ':', 0) Return $macsemicolon EndFunc ;==>_GetMAC
Ghost21 Posted August 28, 2007 Author Posted August 28, 2007 From http://www.autoitscript.com/forum/index.ph...hl=mac++Address Just do $MAC = _GetMAC(1) Func _GetMAC($getmacindex = 1) $ipHandle = Run(@ComSpec & ' /c ipconfig /all', '', @SW_HIDE, 2) $macdashed = StringRegExp(StringStripWS(StdoutRead($ipHandle), 3), '([0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2})', 3) If Not @extended Then Return 0 If Not IsArray($macdashed) Then Return 0 If $getmacindex = 0 Then Return UBound($macdashed) If $getmacindex < - 1 Then Return 0 If $getmacindex > UBound($macdashed) Or $getmacindex = -1 Then $getmacindex = UBound($macdashed) $macsemicolon = StringReplace($macdashed[$getmacindex - 1], '-', ':', 0) Return $macsemicolon EndFunc ;==>_GetMAC Seems like alot of code for just needing to read one line... my line gives you the mac you just have to read 17 characters from a dos window.. but reading from the dos window is what I need help with.. But the code looks nice...
weaponx Posted August 28, 2007 Posted August 28, 2007 (edited) Or you can do it with WMI if you want a lot more info: expandcollapse popup; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE DeviceID = 1", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "AdapterType: " & $objItem.AdapterType & @CRLF $Output = $Output & "AdapterTypeId: " & $objItem.AdapterTypeId & @CRLF $Output = $Output & "AutoSense: " & $objItem.AutoSense & @CRLF $Output = $Output & "Availability: " & $objItem.Availability & @CRLF $Output = $Output & "Caption: " & $objItem.Caption & @CRLF $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF $Output = $Output & "Description: " & $objItem.Description & @CRLF $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF $Output = $Output & "Index: " & $objItem.Index & @CRLF $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output = $Output & "Installed: " & $objItem.Installed & @CRLF $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF $Output = $Output & "MACAddress: " & $objItem.MACAddress & @CRLF $Output = $Output & "Manufacturer: " & $objItem.Manufacturer & @CRLF $Output = $Output & "MaxNumberControlled: " & $objItem.MaxNumberControlled & @CRLF $Output = $Output & "MaxSpeed: " & $objItem.MaxSpeed & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "NetConnectionID: " & $objItem.NetConnectionID & @CRLF $Output = $Output & "NetConnectionStatus: " & $objItem.NetConnectionStatus & @CRLF $strNetworkAddresses = $objItem.NetworkAddresses(0) $Output = $Output & "NetworkAddresses: " & $strNetworkAddresses & @CRLF $Output = $Output & "PermanentAddress: " & $objItem.PermanentAddress & @CRLF $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0) $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF $Output = $Output & "ProductName: " & $objItem.ProductName & @CRLF $Output = $Output & "ServiceName: " & $objItem.ServiceName & @CRLF $Output = $Output & "Speed: " & $objItem.Speed & @CRLF $Output = $Output & "Status: " & $objItem.Status & @CRLF $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF $Output = $Output & "TimeOfLastReset: " & WMIDateStringToDate($objItem.TimeOfLastReset) & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_NetworkAdapter" ) Endif Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc Edited August 28, 2007 by weaponx
Toady Posted August 28, 2007 Posted August 28, 2007 Read at xweapons first post, it shows u how to read from a dos window. Simple IMO. www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding
weaponx Posted August 28, 2007 Posted August 28, 2007 Seems like alot of code for just needing to read one line... my line gives you the mac you just have to read 17 characters from a dos window.. but reading from the dos window is what I need help with..But the code looks nice...A lot of code? That function I showed uses ipconfig which will work on a lot of machines, yours requires something else.You want to see a lot of code? I have 2620 lines of PHP code to clean up just for one page today.
Ghost21 Posted August 28, 2007 Author Posted August 28, 2007 A lot of code? That function I showed uses ipconfig which will work on a lot of machines, yours requires something else.You want to see a lot of code? I have 2620 lines of PHP code to clean up just for one page today.when I say alot of code I'm talking about just being able to read one line... of code from a dos window... is there some kind of read command ???
weaponx Posted August 28, 2007 Posted August 28, 2007 Reading a line is not the problem, when you are dealing with a command line utility 99.9% of the time there is other text piped along with what you need to see, hence RegEx and StringSplit are used to strip off the crap from StdReadOut
Ghost21 Posted August 28, 2007 Author Posted August 28, 2007 Reading a line is not the problem, when you are dealing with a command line utility 99.9% of the time there is other text piped along with what you need to see, hence RegEx and StringSplit are used to strip off the crap from StdReadOutI was thinking something more like #include <constants.au3>$get = RunWait("getmac /S " & @ComputerName & " /FO table /NH")$StdOut = ""While ProcessExists($get) $StdOut = StdoutRead($get)WEndMsgBox(4000, "Results", $StdOut)
Ghost21 Posted August 28, 2007 Author Posted August 28, 2007 I was thinking something more like #include <constants.au3>$get = RunWait("getmac /S " & @ComputerName & " /FO table /NH")$StdOut = ""While ProcessExists($get) $StdOut = StdoutRead($get)WEndMsgBox(4000, "Results", $StdOut)If I'm way off my rocker in thinking it can be done like that just say so...
weaponx Posted August 28, 2007 Posted August 28, 2007 (edited) #include <constants.au3> $get = Run("getmac /S " & @ComputerName & " /FO table /NH", @ScriptDir, @SW_HIDE, $STDOUT_CHILD) While ProcessExists($get) ;Wait for program to finish Sleep(100) WEnd $StdOut = StdoutRead($get) MsgBox(4000, "Results", StringLeft(StringStripWS ($StdOut, 8),17)) Edited August 28, 2007 by weaponx
muhmuuh Posted August 28, 2007 Posted August 28, 2007 I have idea send("#r") sleep(1000) send("cmd") send("{ENTER}") sleep(1000) send("getmac >mac.txt") send("{ENTER}") and than you can get the mac from the txt file I ran. I ran until my muscles burned and my veins pumped battery acid. Then I ran some more.
Ghost21 Posted August 28, 2007 Author Posted August 28, 2007 I have idea send("#r") sleep(1000) send("cmd") send("{ENTER}") sleep(1000) send("getmac >mac.txt") send("{ENTER}") and than you can get the mac from the txt file funny guy ... muhmuuh .. muhmuuh.. muhmuuh WeaponX: That's close but for some reason its not reading the MAc...
PsaltyDS Posted August 28, 2007 Posted August 28, 2007 I was thinking something more like #include <constants.au3>$get = RunWait("getmac /S " & @ComputerName & " /FO table /NH")$StdOut = ""While ProcessExists($get) $StdOut = StdoutRead($get)WEndMsgBox(4000, "Results", $StdOut)You won't $get any results from that. First, RunWait() returns the exit code, not the PID like Run(). Second, without the $STDOUT_CHILD parameter you can't read the STDOUT stream with StdOutRead(). Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
weaponx Posted August 28, 2007 Posted August 28, 2007 The god damn forum always strips off my includes, I edited it.
PsaltyDS Posted August 28, 2007 Posted August 28, 2007 The god damn forum always strips off my includes, I edited it.How many times have you been told? RETRACT the claws before typing! (He loses more keyboards that way...) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Ghost21 Posted August 28, 2007 Author Posted August 28, 2007 The god damn forum always strips off my includes, I edited it.OMFG... WEAPONX... you rock ...#include <constants.au3>$get = Run("getmac /S " & @ComputerName & " /FO table /NH", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)While ProcessExists($get) ;Wait for program to finish Sleep(100)WEnd$StdOut = StdoutRead($get)MsgBox(4000, "Results", StringLeft(StringStripWS ($StdOut, 8),17))THANK YOU THANKYOU THANKYOU... \& thanks Salty for explainging why it wasn't working...
Ghost21 Posted August 28, 2007 Author Posted August 28, 2007 I told you it was the god damn forum! hahahahaOk now that WMI code above looked sweet .. I think i'm going to have to learn that...
PsaltyDS Posted August 28, 2007 Posted August 28, 2007 (edited) I told you it was the god damn forum! Yeah, like it was the forum that shredded my chair you were sitting in last weekend... you can't have adamantium claws and impulse control issues at the same time! Edited August 28, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now