Batch view all IP online conditions under the same subnet _dos/bat

Source: Internet
Author: User
Tags goto ip number

The batch process in this article lets you know what IP is being used under the same network segment of your local area network. I have to admit, I thought it was strange and even stupid when I created this batch.

:::::: View all subnets Ip.bat:::::: @echo off title View all subnets IP set/a online=0 set/a offline=0 set/a total=256 set exportfile= subnet I P Online statistics. txt:: Initialization of online IP and no online IP number is zero, scanning 256 IP, the result output file name set Starttime=%time%:: Recording the start time of the program for/f "delims=: tokens=2"%%i in ( ' Ipconfig/all ^| find/i "IP Address" "Does set ip=%%i:: Obtain native IP [Note 1] if"%ip% "=" "echo is not connected to Network & pause & goto:eof If"%ip% "=" 0. 0.0.0 "Echo is not connected to Network & pause & goto:eof:: When the IP is empty or 0.0.0.0, the prompt is not connected and exits the program for/f" delims=. tokens=1,2,3,4 '%%i in ('%ip% ') do (set/a ip1=%%i set/a ip2=%%j set/a-ip3=%%k set/a ip4=%%l):: With a period of separator, I The four decimal digits of P are assigned to four variables set/a ip4=0 echo online ip:>%exportfile%:: The fourth value of the initialization IP is zero and the resulting output file is created: Retry ping%ip1%.%i P2%.%i P3%.%i p4%-N 1-w 200-l 16>nul && set/a online+=1 && Echo%ip1%.%i P2%.%i P3%.%i p4%>>%exportfile% | | set/a offline+=1:: Ping Destination IP [Note 2] set/p =[replaces the backspace in Comment 4 at the bottom of this article]set/a scanned=%online%+%offline% to set/a (progress= e%+%offline%) *100/%total% set/p = scanning in progress:%scanned%/%total% Scan progress:%progress%%%:: Deletes the contents of the current row and displays the progress information again [Note 3] set/a ip4+=1 if%ip4% LSS%total%:: When IP Fourth
When the number is less than the total, skip back: Retry, repeat until all ping is finished. Echo.

Echo. Set Endtime=%time%:: Recording the end time of the program set/a Seconds =%endtime:~6,2%-%starttime:~6,2% set/a = Minutes-%endtime:~3,2% rttime:~3,2% if%seconds% LSS 0 set/a Seconds + & set/a Minutes-= 1 if%minutes% LSS 0 set/a Minutes + 60:: Calculate Time Difference set/a percent=%online%*100/(%online%+%offline%):: Calculating online percent echo online IP number:%online% echo not line IP number:%offline% echo Online Percent:%percent%%% echo Statistics time consuming:%minutes% minute%seconds% sec echo Statistic Date:%date%%time:~0,-3% echo.>>%exportfile% echo Online IP number :%online%>>%exportfile% echo not in line IP:%offline%>>%exportfile% echo online percent:%percent%%%>>%exportfile % echo Statistics time consuming:%minutes% minutes%seconds% seconds >>%exportfile% echo statistic date:%date%%time:~0,-3%>>%exportfile% echo record saved to file

 %exportfile%:: Displays the results and saves the results to the file pause::::::::::::.:::;.:;

Note 1. Ipconfig is a TCP/IP application built into Windows that displays configuration information such as the physical address and IP address of the local computer network adapter, which is typically used to verify that the manually configured TCP/IP settings are correct. When using the DHCP service on a network, ipconfig can detect what IP addresses are assigned to the computer, are configured correctly, and can release and regain IP addresses. This information plays an important role in network testing and troubleshooting. [3]
For more detailed instructions, see ipconfig/? Ipconfig/all, the parameter/all represents viewing the detailed network configuration. Command Ipconfig/all ^| find/i "IP Address" is the result of the ' Ipconfig/all ', which looks for the object as "IP address" (the result is similar to: IP address. ...........:10.30.11 .51).

The For statement in the entire command, in the above result, takes a colon interval (delims=:) to find the 2nd string (tokens=2). Obviously, the result is the current IP address of your computer (if you have only one network card or only one NIC enabled). Obviously, for multiple network cards will show a number of IP situation, I did not consider too comprehensive. [For more details see 4.2.4 section]

Also, note that in Ipconfig/all ^| find/i "IP Address" has an escape character ^, its function is to let the following pipeline command | Take effect instead of letting the program put | Misunderstood as part of the parameter in the For statement.

Note 2. Ping is actually the core part of this batch. The primary role of the command ping is to detect whether the network is connected between two computers by sending a packet and receiving an answer message. For example, I can enter ping 10.30.11.35 to see if I can connect to the IP-10.30.11.35 machine in my local area network. If I do not understand batch processing, perhaps I have to start from the IP 10.30.11.1, ping to the IP 10.30.11.255, in order to achieve my original purpose in this section.

3 parameters for ping in batch-n 1-w 200-l 16 respectively: Ping only once [-N 1], wait 200 milliseconds, and then consider [-W 200] and send 16 bytes of data [-L 16].

In addition, the command line also uses two && and one | | Combination command, I have to admit that this complex logical relationship will bring you difficulty in reading.

Note 3. The set/p = display content is used here

The use of this article is not very large, but interesting, at least not as stupid as imagined.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.