2015年1月9日 星期五

一次啟動 500 thread ping Class B subnet

以下為一次啟動 500  thread 同時ping

1.寫script印出所有IP
vi print_allip.sh
*************************************************************
#!/bin/bash

for j in {0..255}
do
        for i in {0..255}
        do
        echo "172.16.$j.$i"
        done
done
*************************************************************

./print_allip.sh > allip.txt

2.同時啟動 500  thread....
cat  allip.txt  | xargs -n 1 -I ^ -P 500 ping -c 1 ^ > res.txt &

3.找出活著的主機
grep "icmp_req=1" res.txt  > alive.txt

4.排序

sort -t . -k 3,3n -k 4,4n alive.txt


Where,
  • -t . : Set field to . (dot) as our IPs separated by dot symbol
  • -n : Makes the program sort according to numerical value
  • -k opts: Sort data / fields using the given column number. For example, the option -k 2 made the program sort using the second column of data. The option -k 3,3n -k 4,4n sorts each column. First it will sort 3rd column and then 4th column.



排序windows  dhcp dump file:
sort -n -t. -k10,10  -k11,11 dhcp.txt



5. 只留下IP
awk '{print $4}' alive.txt > alive-ip.txt

=======================================
以下script為一台一台ping 效率很差
#!/bin/bash

for j in {0..255}
do
        for i in {0..255}
        do
        ping -c 1 "172.22.$j.$i" > /dev/null
          [ $? -eq 0 ] && echo Node with IP: 172.16.$j.$i is up.
        done
done

=======================================
使用 SED 移除空白行
sed '/^$/d' filename.txt

Remove the line containing the string "awk": 
sed '/awk/d' filename.txt

沒有留言:

張貼留言