cowsmanaut Posted June 27, 2006 Share Posted June 27, 2006 dunno if this is usefull to anyone but I made this thing after plenty of help from others and the wonderfull help file I basically takes a list of local computers and sends a request for their IP and MAC address and then pipes all that information from them to a Text file. I tried to fully comment everything so it should be easy to read. You need psexec.exe to get it to work. This is part of the free pstools suite. http://www.sysinternals.com/Utilities/PsTools.htmlenjoyexpandcollapse popup#include <array.au3> #include <file.au3> ;setting the array for the list of computers you want checked Dim $DigCtrl[1] _ArrayAdd($DigCtrl, "digi01") _ArrayAdd($DigCtrl, "digi02") _ArrayAdd($DigCtrl, "digi03") _ArrayAdd($DigCtrl, "digi04") _ArrayAdd($DigCtrl, "digi05") _ArrayAdd($DigCtrl, "digi06") $DigCtrl[0] = UBound($DigCtrl) - 1 Dim $DigData[$DigCtrl[0] + 1] $DigData[0] = $DigCtrl[0] ;Making a file to place the collected info _FileCreate ( "c:\IPlist.txt" ) $fileb = FileOpen("c:/IPlist.txt", 1) ; Display original array For $var = 1 To UBound($DigCtrl) -1 $data = $DigCtrl[$var] ;send ipconfig request to selected computer using psexec.exe from my c:/au3_tool folder. Run(@ComSpec & ' /c c:\au3_tool\psexec \\' & $data & ' -u Administrator -p PASSWORD ipconfig /all > c:/ip.txt', '', @SW_HIDE) ;this can be commented out it's for feedback so you know it's collecting them or not MsgBox ( 0, $data , ipget () ) ;Writing the info to the file FileWrite($fileb, ipget () & @CRLF) Next ;Close the file because we are done with it FileClose($fileb) func ipget() ;open the file $file = FileOpen("c:/ip.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ;Timer Variable set at 0 outside loop to reset it $ass = 0 ; Read in lines 34 and 40 $vara = FileReadLine($file, 34) If @error = -1 Then do ;start timer $ass = $ass + 1 ;send ipconfig request to selected computer again untill it works or I give up Run(@ComSpec & ' /c c:\au3_tool\psexec \\' & $data & ' -u Administrator -p bu330ff ipconfig /all > c:/ip.txt', '', @SW_HIDE) $vara = FileReadLine($file, 34) ;reads from the string which should be Pyhisical address ...... etc for the first 9 characters $result = StringLeft($vara, 9) ;there is a lot of spaces and then the P so it will look for that or keep counting to 50 Until $result = " P" or $ass = 50 EndIf ;if it gives up set values to "unknown" $varb = FileReadLine($file, 40) If @error = -1 Then $varb = ": unknown" If @error = -1 Then $vara = ": unknown" ;removes un-needed text $chara = StringRight($vara, 20) $charb = StringRight($varb, 14) ;Setting it to a readable format replacing the MAC and IP titles $ipinf = $data & @CRLF & "Mac: " & $chara & @cr & "IP: " & $charb ;MsgBox(0, $data, $data & " information:" & @cr & @cr & $chara & @cr & $charb) Return $ipinf FileClose($file) EndFunc Link to comment Share on other sites More sharing options...
ptrex Posted June 27, 2006 Share Posted June 27, 2006 @cowsmanaut nice script but it's a little overkill to use an external appl. to get the info, if you can without it. expandcollapse popup; ---------------------------------------------------------------------------- ; ; IPConfig Data V1.0 by ptrex ; ; ---------------------------------------------------------------------------- #include <date.au3> Dim $strComputer = "IP ADDRESS HERE" Dim $objWMIService, $colAdapters, $n Dim $utcLeaseObtained, $utcLeaseObtained, $utcLeaseExpired, $strLeaseObtained, $utcLeaseExpires, $strLeaseExpires $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colAdapters = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True") $n = 1 For $objAdapter in $colAdapters ConsoleWrite ("Network Adapter " & $n & @CR) ConsoleWrite ("================="& @CR) ConsoleWrite (" Description: " & $objAdapter.Description& @CR) ConsoleWrite (" Physical (MAC) address: " & $objAdapter.MACAddress& @CR) ConsoleWrite (" Host name: " & $objAdapter.DNSHostName& @CR) If Not ($objAdapter.IPAddress) = " " Then For $i = 0 To UBound($objAdapter.IPAddress) ConsoleWrite (" IP address: " & $objAdapter.IPAddress($i)& @CR) Next EndIf If Not ($objAdapter.IPSubnet) = " " Then For $i = 0 To UBound($objAdapter.IPSubnet) ConsoleWrite (" Subnet: " & $objAdapter.IPSubnet($i)& @CR) Next EndIf If Not ($objAdapter.DefaultIPGateway) = " " Then For $i = 0 To UBound($objAdapter.DefaultIPGateway) ConsoleWrite (" Default gateway: " & _ $objAdapter.DefaultIPGateway($i)& @CR) Next EndIf ConsoleWrite (" DNS"& @CR) ConsoleWrite (" ---"& @CR) ConsoleWrite (" DNS servers in search order:"& @CR) If Not ($objAdapter.DNSServerSearchOrder) = " " Then For $i = 0 To UBound($objAdapter.DNSServerSearchOrder) ConsoleWrite (" " & $objAdapter.DNSServerSearchOrder($i)& @CR) Next EndIf ConsoleWrite (" DNS domain: " & $objAdapter.DNSDomain& @CR) If Not ($objAdapter.DNSDomainSuffixSearchOrder) = " " Then For $i = 0 To UBound($objAdapter.DNSDomainSuffixSearchOrder) ConsoleWrite (" DNS suffix search list: " & _ $objAdapter.DNSDomainSuffixSearchOrder($i)& @CR) Next EndIf ConsoleWrite (" DHCP"& @CR) ConsoleWrite (" ----"& @CR) ConsoleWrite (" DHCP enabled: " & $objAdapter.DHCPEnabled& @CR) ConsoleWrite (" DHCP server: " & $objAdapter.DHCPServer& @CR) If Not ($objAdapter.DHCPLeaseObtained) = " " Then $utcLeaseObtained = $objAdapter.DHCPLeaseObtained $strLeaseObtained = WMIDateStringToDate($utcLeaseObtained) Else $strLeaseObtained = "" EndIf ConsoleWrite (" DHCP lease obtained: " & $strLeaseObtained& @CR) If Not ($objAdapter.DHCPLeaseExpires) = " " Then $utcLeaseExpires = $objAdapter.DHCPLeaseExpires $strLeaseExpires = WMIDateStringToDate($utcLeaseExpires) Else $strLeaseExpires = "" EndIf ConsoleWrite (" DHCP lease expires: " & $strLeaseExpires& @CR) ConsoleWrite (" WINS"& @CR) ConsoleWrite (" ----"& @CR) ConsoleWrite (" Primary WINS server: " & $objAdapter.WINSPrimaryServer& @CR) ConsoleWrite (" Secondary WINS server: " & $objAdapter.WINSSecondaryServer& @CR) $n = $n + 1 Next Func WMIDateStringToDate($utcDate) Local $Return $Return = (StringMid($utcDate, 5, 2) & "/" & _ StringMid($utcDate, 7, 2) & "/" & _ StringLeft($utcDate, 4) & " " & _ StringMid ($utcDate, 9, 2) & ":" & _ StringMid($utcDate, 11, 2) & ":" & _ StringMid($utcDate, 13, 2)) Return $Return EndFunc Enjoy !! Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
cowsmanaut Posted June 27, 2006 Author Share Posted June 27, 2006 ERROR:$colAdapters = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")$colAdapters = $objWMIService.E^Unable to parse lineI get this error when I try to run Link to comment Share on other sites More sharing options...
ptrex Posted June 28, 2006 Share Posted June 28, 2006 @cowsmanaut My dear friend you have to fill in the CORRECT IP ADDRESS in line 9 !! m $strComputer = "IP ADDRESS HERE" should be m $strComputer = "10.0.0.1" or something. I hope this helps. Regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
cowsmanaut Posted June 29, 2006 Author Share Posted June 29, 2006 for the computer I want? The idea here was to find the IP and MAC from the computers by only knowing their network name. so if you have a series of computers, as I do in my lab but they get IP through DHCP and sometimes the computer services people change stuff.. then I can find out what ip if any they are getting. The reason I needed to use PSexec is to run ipconfig on a networked machine rather than having to be at it's console. Not because it was needed to get the IP or MAC... also because it's a secure network you need to submit admin account and password to get to each machine which PSexec supports by adding the flag -u and -p for user and password. I don't fully understand your script at the moment but seems like it's for the computre you are currently sitting at. Or I could be completely confused.. and it does look at all local networked machines and gives me their info? I guess it's just a matter of fully understanding all the commands you are using. I'm certainly open to a better way if you have one. As I would like to not have to use PSexec for this. However, based on the criteria I didn't know how else to get it working. Link to comment Share on other sites More sharing options...
nitekram Posted June 29, 2006 Share Posted June 29, 2006 Have you wrote this for a range of IP address - that way you would only have to know the subnet and it would then tell you each machine on the network - maybe add the DNS name. Like a network scanner, but made with AutoIT. 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow."  WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI  CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
ptrex Posted June 29, 2006 Share Posted June 29, 2006 @cowsmanautThe idea here was to find the IP and MAC from the computers by only knowing their network nameFill in the NETWORK NAME or IP ADDRESS.Works both ways. Why did you not try it before replying ? What' s there to understand it gives you the same details as you would get from the CONSOLE ?Why make life complex by using external applicatiosns if AutoIT can give it all without depending in anything else. Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
cowsmanaut Posted June 30, 2006 Author Share Posted June 30, 2006 (edited) @cowsmanautFill in the NETWORK NAME or IP ADDRESS.Works both ways. Why did you not try it before replying ? What' s there to understand it gives you the same details as you would get from the CONSOLE ?Why make life complex by using external applicatiosns if AutoIT can give it all without depending in anything else. I didn't try because the computers were at work and I wasn't there for a while to be able to try it. I did try it now however, I tried both IP address and network name and I again get the "unable to parse" error for line 16. used Dim $strComputer = "10.115.7.51"and then triedDim $strComputer = "\\digi02"and also triedDim $strComputer = "digi02"I should point out that while I am learning and trying to use this scripting. I'm by no means a computer programmer. I'm a 3D artist. Limited scripting is requried in 3D and in this particular case I'm trying to do something to manage the lab I'm working in because of some IP conflicts when we reinstall all the computers. It's more of a learning out of necessity thing for me. So I'm liable to be a bit slow in the understanding of some concepts.Also the amount of time I use this for is usually a couple of months a year when we go through and update the process and change scripts etc. Then I don't do it again for the rest of theyear and forget half of what I learned in the first place. So please be patient with me. if you would like to see what I normally do for fun then you can look here. http://cowsmanaut.gfxartist.com some of you guys script for fun.. I paint. Edited June 30, 2006 by cowsmanaut Link to comment Share on other sites More sharing options...
w0uter Posted July 3, 2006 Share Posted July 3, 2006 Why doesnt anyone tell him this: You need the beta version. My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
HELSAY Posted July 20, 2006 Share Posted July 20, 2006 to cowsmanaut You don't need any ip address (IPA) or computer name (CN) to test the code, just do this : Dim $strComputer = "Localhost" LocalHost means there is always an IPA : 127.0.0.1 if not connected to a network or an IPA automatically taken by your network adaptator from your modem (router,...), or one that you statically encoded. TO see the result of ipconfig.au3, make this changes in the source (I'm using scite) 1. replace all @CR by @CRLF (carriage return / Line feed) --> in scite CTRL+H --> find What = @CR and Replace with = @CRLF --> then replace all 2. ALWAYS compile all your au3 files using the latest version (including beta !!!) so check download section for beta installs 3. once compiled (ALT+F7 in scite), go to the directory in "DOS mode" : click on Windows Start / choose Run and type : %comspec% and then press Enter A black "Dos" Windows is now running command line if you have compiled ipconfig.au3 in c:\MyProgs\ipconfig.exe then just type, in this "Dos box", the following commands : CD\MyProgs (ENTER Key) IPCONFIG >test.txt (ENTER Key) exit To see the results, uses Windows Explorer to open the file test.txt Nota.: if there is spaces in your path, do this : "CD\My Prog Path With Spaces\Other Dir\" --> quotes needed ! Hope every things right ... Logicae Homo EstFemina Homo EstFemina Logicae Est Link to comment Share on other sites More sharing options...
archrival Posted July 25, 2006 Share Posted July 25, 2006 Why not use ARP to retrieve the MAC address? Link to comment Share on other sites More sharing options...
HELSAY Posted July 31, 2006 Share Posted July 31, 2006 Fine code but still external to autoit ... This is a Batch Scritp, you can add it to apps by reading the TEXT file.It will also display the NIC, i always use it with autoit as it shows the main NIC settings.-------------------------------------network.bat-----------------------------------------@ECHO OFFREM **********************************REM * Author: Donald Muir *REM * Date: 12 June 2006 *REM * *REM **********************************DEL NET.txtipconfig/all | FIND /I "IP Address">> IP.txtfor /f " tokens=14* delims=, " %%i in (IP.txt) DO SET IPAddress=%%jecho %IPAddress%>> NET.txtDEL IP.txtipconfig/all | FIND /I "Subnet Mask">> SUB.txtfor /f " tokens=14* delims=, " %%a in (SUB.txt) DO SET SUBAddress=%%becho %SUBAddress%>> NET.txtDEL SUB.txtipconfig/all | FIND /I "Default Gateway">> GATE.txtfor /f " tokens=12* delims=, " %%k in (GATE.txt) DO SET GATAddress=%%lecho %GATAddress%>> NET.txtDEL GATE.txtNBTSTAT -a %IPAddress% | FIND /I "MAC Address">> MAC.txtfor /f " tokens=3* delims=, " %%i in (MAC.txt) DO SET MACAddress=%%jecho %MACAddress%>> NET.txtDEL MAC.txTipconfig/all | FIND /I "Description">> card.txtfor /f " tokens=13* delims=, " %%k in (card.txt) DO SET netcard=%%lecho %netcard%>> NET.txtDEL card.txtipconfig/all | FIND /I "DNS Servers">> dns.txtfor /f " tokens=14* delims=, " %%k in (dns.txt) DO SET netdns1=%%lecho %netdns1%>> NET.txtDEL dns.txt----------------------------------------------end network.bat-----------------------------------CheersDwalf Logicae Homo EstFemina Homo EstFemina Logicae Est Link to comment Share on other sites More sharing options...
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