In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to implement batch processing to view all IP online conditions under the same subnet". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
: view all subnet IP.bat:@echo offtitle view all subnet IPset / an Online=0set / an Offline=0set / a Total=256set ExportFile= subnet IP online statistics. Txt:: the number of initialized online IP and offline IP is zero, a total of 256IP are scanned The resulting output file name set StartTime=%time%:: logger start time for / f "delims=: tokens=2"% I in ('ipconfig / all ^ | find / I "IP Address"') do set IP=%%i:: gets native IP [Note 1] if "% IP%" = "echo is not connected to the network & pause & goto: EOFif"% IP% "=" 0.0.0.0 "echo is not connected to the network & pause & Goto: EOF:: when IP is empty or 0.0.0.0 Prompt not to connect and exit the program for / f "delims=. Tokens=1,2,3,4 "% I in ("% IP% ") do (set / an IP1=%%i set / an IP2=%%j set / an IP3=%%k set / an IP4=%%l):: assign the four decimal numbers of IP to the four variables set / an IP4=0echo online IP: >% ExportFile%:: initializes the fourth value of IP to zero with a period as the separator And create the result output file: RETRYping% IP1%.%IP2%.%IP3%.%IP4%-n 1-w 200-l 16 > nul & & set / an Online+=1 & & echo% IP1%.%IP2%.%IP3%.%IP4% > >% ExportFile% | | set / an Offline+=1:: ping target IP [Note 2] set / p = [replace the backspace character in comment 4 at the bottom of this article here] set / a Scanned=%Online%+%Offline%set / a Progress= (%) Online%+%Offline%) * 100/%Total%set / p = scanning:% Scanned%/%Total% scan progress:% Progress%%%:: deletes the contents of the current line And redisplay the progress information [Note 3] set / an IP4+=1 if% IP4% lss% Total% goto: RETRY:: when the fourth value of IP is less than the total, jump back to: RETRY Repeat the end time of the echo.echo.set EndTime=%time%:: record program set / a Seconds =% EndTime:~6,2% -% StartTime:~6,2%set / a Minutes =% EndTime:~3,2% -% StartTime:~3,2%if% Seconds% lss 0 set / a Seconds + = 60 & set / a Minutes-= 1if% Minutes% lss 0 set / a Minutes + = 60 Seconds: calculation time difference set / a Percent=%Online%*100/ (% Online%+%Offline%):: calculate online percentage echo online IP:% Online%echo offline IP:% Offline%echo online percentage:% Percent%%%echo Statistics time:% Minutes% minutes% Seconds% seconds echo Statistical date:% date%% time:~0 -3%echo. > >% ExportFile%echo online IP:% Online% > >% ExportFile%echo offline IP:% Offline% > >% ExportFile%echo online percentage:% Percent%%% > >% ExportFile%echo Statistics time:% Minutes% minutes% Seconds% seconds > >% ExportFile%echo Statistics date:% date%% time:~0 -3% > >% ExportFile%echo record saved to the file "% ExportFile%":: display the results and save the results to the file pause::
Note 1. Ipconfig is a TCP/IP application built into Windows to display configuration information such as the physical address and IP address of the local computer network adapter, which is generally used to verify that the manually configured TCP/IP settings are correct. When using the DHCP service in the network, ipconfig can detect what IP address is assigned to the computer, whether it is configured correctly, and can release and reacquire the IP address. This information plays an important role in network testing and troubleshooting. [3]
See ipconfig/? for more detailed instructions. Ipconfig / all. Parameter / all means to view the detailed network configuration. The command ipconfig / all ^ | find / I "IP Address" means that in the result of 'ipconfig / all, search with "IP Address" (the result is similar to: IP Address.: 10.30.11.51).
The for statement in the entire command indicates that in the above result, look for the second string (tokens=2) with the colon as the interval (delims=:). Obviously, what you find is the current IP address of your computer (if you only have a fast network card or only one network card is enabled. Obviously, I have not considered the situation that multiple network cards will show multiple IP. [see section 4.2.4 for more details on for]
In addition, notice that there is an escape character ^ in ipconfig / all ^ | find / I "IP Address". Its purpose is to make the subsequent pipe command | take effect, rather than let the program misinterpret the | as part of the parameter in the for statement.
Note 2. Ping is actually the core part of this batch. The main function of the command ping is to detect whether the network between the two computers is connected by sending data packets and receiving reply messages. For example, I can type ping 10.30.11.35 to see if I can connect with the machine in my local area network whose IP is 10.30.11.35. If I don't understand batch processing, I may have to start with IP 10.30.11.1 and ping one by one to IP 10.30.11.255 to achieve my original purpose in this section.
In the batch processing, the three parameters of ping-n 1-w 200-l 16 respectively mean: ping only once [- n 1], wait 200ms and then consider the timeout [- w 200] and send 16 bytes of data [- l 16].
In addition, this command line uses a combination of two & & and one | commands, and I have to admit that this complex logical relationship can make it difficult for you to read.
Note 3. Set / p = is used here to display the content
This is the end of the content of "how to implement batch processing to view all IP online under the same subnet". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.