| 1. |
Solve : How Can I get IP and MAC address for remote PCs over the network by batch file? |
|
Answer» Hi All,
but you didn't get my point, I want to get all Hostnames located inside the text file then process it by bat file then output to another text file SORTED looks like that Hostname: IP: MAC for each hostFirst , You should make an effort and show us your try with your own code ! May be this can help you to construct your own code : How to USE an IP Address to Find a MAC Address He doesn't try...he just wants people writing code for him... Not once has he posted anything he did himself. Quote from: Hackoo on December 31, 2020, 12:47:35 PM First , You should make an effort and show us your try with your own code ! Dear Hacoo Thanks for your gentle reply and here is my code echo off echo All Information >"Hosts Info.txt" echo. >>"Hosts Info.txt" For /f %%d in (hosts.txt) do ( echo. %%d >>"Hosts Info.txt" getmac /s %%d /v /nh >>"Hosts Info.txt" ping %%d |find "Ping statistics for" >>"Hosts Info.txt" echo._______________________________ >>"Hosts Info.txt" ) pause exit but it's so dummied as I don't know but a few things about the batch programming, so I'm trying to do my best and I can't deal ever with many things like ( "tokens & delims" , " ~ " , " 1% " , " find "," findstr" ) What is these things means and how we use it But I try to find what I want from some people's ideas and try to imitate them in some codes, but I do not reach the DESIRED result most of the time due to my ignorance of most of the language of the batch files but I'm still trying to learn - The previous getmac code give me the whole NIC MAC with manufacturere with many details For example: Ethernet Intel(R) Ethern 8C-Df-D5-4e-a8-72 \Device\Tcpip_{817345F1-e93E-44D7-B19a-70F0f4F73Ec4} and i want only tha mac address 8C-Df-D5-4e-a8-72 And The previous Ping code give me also the whole the Ping statistics result for Example : Ping statistics for 172.217.17.238: and i just need the IP only like that 172.217.17.238 And finally if you can to help me to put all the results to gether in one line you are highly appretiated and if you won't also you are highly appretiated for the previous & gentle help Ok, First, we should proceed to your problem step by step What result did you get when you type this command with your cmd ? Code: [Select]getmac /s localhost /v /nh /fo csv | find /I "N/A"Unfortunately after tried this code on my PC at home I didn't get anything even after saving the result into a text file as attached screenshot, so I'll go to my work tomorrow then I'll try the same code again on any workstation inside my domain and feed back to you with the result Quote from: Abo-Zead on January 02, 2021, 07:51:25 AM Unfortunately after tried this code on my PC at home I didn't get anything even after saving the result into a text file as attached screenshot, so I'll go to my work tomorrow then I'll try the same code again on any workstation inside my domain and feed back to you with the resultNo problem; can you post me the result of this command without find /I "N/A" I mean like this : Code: [Select]getmac /s localhost /v /nh /fo csvI got as result like this one : Code: [Select]"Ethernet","Broadcom NetLink (TM) Gigabit Ethernet","XX-XX-XX-XX-XX-XX","Support déconnecté" "Wi-Fi","Qualcomm Atheros AR5BWB222 Wireless Network Adapter","XX-XX-XX-XX-XX-XX","N/A" "Ethernet 2","TAP-Windows Adapter V9","XX-XX-XX-XX-XX-XX","Support déconnecté" "Connexion réseau Bluetooth","Bluetooth Device (Personal Area Network)","XX-XX-XX-XX-XX-XX","Support déconnecté"After using this code I got that result now "Ethernet","Intel(R) Ethernet Connection I217-LM","XX-XX-XX-XX-XX-XX","\Device\T cpip_{827317F1-C9XX-XXD9-BXXD-7XXX9BXXXXE4}" "Ethernet 2","TeamViewer VPN Adapter","XX-FF-A7-XX-XX-XX","Media disconnected" "vEthernet (Default Switch)","Hyper-V Virtual Ethernet Adapter","00-15-5D-XX-XX- 32","\Device\Tcpip_{AXXXXDE8-6B77-4XX3-A2XX-XXXF376BXX7F}" "vEthernet (External switch 1)","Hyper-V Virtual Ethernet Adapter #2","XX-XX-XX- XX-XX-XX","\Device\Tcpip_{XXXD4XXX-CXXF-XXDA-97XX-CXXA7946XXX}"Any Idea, How to reduce the output to required needed IP and MAC only Quote from: Abo-Zead on January 03, 2021, 01:31:18 AM Any Idea, How to reduce the output to required needed IP and MAC onlyTry this batch to EXTRACT only MAC and reduce the output result: Code: [Select]echo off Title Extracting only MAC Address from GetMac Command ( for /f "tokens=3 delims=," %%a in ('getmac /s localhost /v /nh /fo csv') do echo %%~a )>"%~dp0MAC-Address.txt" If Exist "%~dp0MAC-Address.txt" Start "" "%~dp0MAC-Address.txt" & Exit Quote from: Hackoo on January 03, 2021, 02:56:41 AM Try this batch to extract only MAC and reduce the output result: Thanks, Hackoo After test your code it works in my workplace but it doesn't work on my PC at home so maybe the problem in my OS at home Kindly how we put this code under for loop? as it does not work with me in my code below Code: [Select]echo off for /f %%i in (hosts.txt) do ( Title Extracting only MAC Address from GetMac Command ( for /f "tokens=3 delims=," %%a in ('getmac /s localhost /v /nh /fo csv') do echo %%~a )>"%~dp0MAC-Address.txt" ) If Exist "%~dp0MAC-Address.txt" Start "" "%~dp0MAC-Address.txt" & Exit also how we can put it with the Hostname and IP in the same row to look like that as I asked in my first question? Hostname: IP: MAC AddressRefer to this thread How to get MAC address of remote computer Suppose that you a have the inputfile with computers or ip address list, you can give a try with batch file : Hosts.txt Code: [Select]192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4 192.168.1.5 192.168.1.6 192.168.1.7 192.168.1.8 192.168.1.9 192.168.1.10 192.168.1.11 192.168.1.12 192.168.1.13 192.168.1.14 192.168.1.15 192.168.1.16 192.168.1.17 192.168.1.18 192.168.1.19 192.168.1.20IP-MAC-Scan.bat Code: [Select]echo off Set "Copyright=by Hackoo 2021" Title Get IP and MAC address for remote PCs over the network using batch %Copyright% Mode con cols=90 lines=12 cls & color 0A & echo. echo ******************************************************************************** echo Get IP and MAC address for remote PCs over the network %Copyright% echo ******************************************************************************** echo( if _%1_==_Main_ goto :Main :getadmin echo %~nx0 : self elevating set vbs=%temp%\getadmin.vbs ( echo Set UAC = CreateObject^("Shell.Application"^) echo UAC.ShellExecute "%~S0", "Main %~sdp0 %*", "", "runas", 1 )> "%vbs%" "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" goto :eof ::------------------------------------------------------------------------------------- :Main set "InputFile=%~dp0Hosts.txt" set "OutPutFile=%~dp0IP-MAC.txt" If Exist "%OutPutFile%" Del "%OutPutFile%" If Not Exist "%InputFile%" ( color 0C & echo "%InputFile%" does not exist. Please check it first ! Timeout /T 8 /NoBreak>nul & Exit ) Netsh interface ip delete arpcache >nul 2>&1 for /f "tokens=* delims=" %%H in ('Type "%InputFile%"') do ( Ping -n 1 %%H>nul for /f "tokens=2" %%M in ('arp -a %%H ^| find "%%H"') do ( echo %%H : %%M echo %%H : %%M>>"%OutPutFile%" ) ) If Exist "%OutPutFile%" Start "" "%OutPutFile%" & Timeout /T 1 /NoBreak>nul & Exit ::-------------------------------------------------------------------------------------Appreciate your effort Hackoo but after test this code in some workstation inside the domain it gives me this message ARP: Bad argument: %hostname% I don't know why?Hackoo After a lot of searches, I found the below code Code: [Select] ECHO OFF For /f %%a in (hosts.txt) do ( ping -n 1 %%a | for /f "tokens=1-4* delims=: " %%i in ('find "Reply"') do ( nbtstat -a %%a | for /f "tokens=1-2 delims=^=" %%x in ('find "MAC Address"') do ( echo [ %%a : %%k : %%y ]>> Host_IP_MAC.txt echo [ %%a : %%k : %%y ] ) ) ) and after testing I found it works only with all workstations working under WinXp only and the rest of the workstations working under Win7, 8, 8.1, and 10 doesn't work, so kindly help If you have an idea to fix this bug.I don't quite understand how you solved your problem? Like you, I have many different hostnames, but I do not know how to get information about all of them at once. Unfortunately, I do not understand the software part at all. This was done by my partner, who literally went on vacation two days ago. Therefore, I am literally at a dead end, I hope it will not be difficult for you to suggest a solution to my problem. I thought that I could somehow call all the hosts I needed using 192.168, but unfortunately I didn't succeed. So I stopped trying to do something by myself. Nowadays, literally any problem can be solved via the Internet, so I thought that my problem could also be solved. |
|