Linux基础回顾

常用命令

cmddespdesp1example
find文件查找find path -option [-print] [ -exec -ok command ] {}find ./ -name "*.txt" -size -512k -perm 644 #找到以txt结尾的内存小于512k的可读(644)写文件
grep字符串查找grep [OPTION]... PATTERNS [FILE]...grep --max-count=5 -n --context=1 -w "root" .bash_history # 查找前5个root
sedsed -e '1,10d' -e 's/oldstr/newstr/g'
awk
cut字符串编辑cut -d'|' -f4
sort排序sort -t'|' -k4n
tee从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成文件

bash回顾

ping网段主机

功能类似 fping -a -g 192.168.1.129 192.168.1.150

#!/bin/bash                                        # 解释器
if [ "$1" == "" ]                                  # 参数判断
then
  echo "Usage: ./test.sh [ips]"
  echo "Example: ./test.sh 192.168.1"
else
  for x in `seq 129 150`;do                       
    ping -c 1 $1.$x
  done
fi

执行测试

root@yue:~/Documents/read/books/渗透测试/bash# ./ping.sh 192.168.1
PING 192.168.1.129 (192.168.1.129) 56(84) bytes of data.
64 bytes from 192.168.1.129: icmp_seq=1 ttl=64 time=1.07 ms

--- 192.168.1.129 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 1.067/1.067/1.067/0.000 ms
PING 192.168.1.130 (192.168.1.130) 56(84) bytes of data.
64 bytes from 192.168.1.130: icmp_seq=1 ttl=64 time=35.7 ms

--- 192.168.1.130 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 35.659/35.659/35.659/0.000 ms
PING 192.168.1.131 (192.168.1.131) 56(84) bytes of data.
64 bytes from 192.168.1.131: icmp_seq=1 ttl=64 time=1529 ms

--- 192.168.1.137 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
结果处理

通过简单分析,64 bytes from 192.168.1.131: icmp_seq=1 ttl=64 time=1529 ms 为对方应答,表示在线

代码优化

#!/usr/bin/env bash
ping -c 1 $1.$x | grep "64 bytes" | cut -d"" -f4 | sed 's/\:$//'

文件处理

#!/bin/bash
bak=$IFS                     # 定义一个变量bak保存IFS的值
IFS=$'\n'                      # 将环境变量IFS的值修改为换行符
for line in `sed -e '1,15d' ~/Downloads/simpread.md | sort  -t '|'  -k4n`;do
  line=${line// /}
  IFS=$'|'
  line_arr=($line)      # 以IFS作为分割符,形成数组起始下标:0 ok
  if [[ "${line_arr[1]}" == "10↑/10↑/10↑/10↑" ]]; then
    ip=${line_arr[2]}
    port=${line_arr[3]}
    passwd=${line_arr[4]}
    enc=${line_arr[5]}
    country=${line_arr[7]}
    echo -e "$country ip: $ip:$port\t$enc\t$passwd"
    if [[ "$country" == "JP" && "$port"=="8099" ]]; then
      str="{\n\t\"server\":\"$ip\",\n\t\"server_port\":$port,\n\t\"local_port\":1080,\n\t\"password\":\"$passwd\",\n\t\"timeout\":600,\n\t\"method\":\"$enc\"\n}"
      echo -e $str > ~/shadowsocks/$ip.$port.json
    fi
  fi
done
IFS=$bak                    #将环境变量IFS的值改回原值

源文件:
在这里插入图片描述
处理结果:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值