tee sshx.sh <<-'EOF'
#!/bin/bash
whoip=`who am i |awk -F '[()]' '{print $2}'`
city=`curl -s https://ip.cn/index.php?ip=$whoip | grep 'id="tab0_address"' | cut -b 44-74 | sed s/[[:space:]]//g`
hostnam=`hostname`
ip=`ifconfig eth0|awk -F '[ :]+' 'NR==2 {print $3}'`
who=`whoami`
timers=`date '+%Y-%m-%d-%H:%M:%S'`
#msg='请检查服务器登录用户:\n主机名: '`hostname`'\n主机IP: '`ifconfig eth0|awk -F '[ :]+' 'NR==2 {print $3}'`'\n登录用户: '`whoami`'\n登录IP: '`who am i |awk -F '[()]' '{print $2}'`'\n登录时间: '`date '+%Y-%m-%d-%H:%M:%S'`''
token="4f5e208c-1108-4a94-a8d2-12fab9ba2"
curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='$token'' \
-H 'Content-Type: application/json' \
-d '
{
"msgtype": "markdown",
"markdown": {
"content": "#### 主机名:'$hostnam'
>### 主机IP:'$ip'
>### 登录用户:'$who'
>### 登录IP: '$whoip'
>### 登录时间:'$timers'
>### 来自:'$city'"
}
}' >/dev/null 2>/dev/null
exit 0
EOF
/bin/bash /root/wxchat.sh
curl ident.me
curl icanhazip.com
curl whatismyip.akamai.com
curl tnx.nl/ip
curl myip.dnsomatic.com
cat access.log | awk '{print $1}' | sort | uniq -c | sort -nr | awk '{print $2}' > log.txt
#!/bin/bash
for ip in `cat log.txt`; do
iplist=`curl -s --user-agent foobar https://ip.cn/index.php?ip=$ip | grep 'id="tab0_address"' | cut -b 44-77 | sed s/[[:space:]]//g`
echo "$ip >>$iplist"
#curl -s --user-agent foobar https://ip.cn/index.php?ip=$ip|grep '所在地理位置'|awk -F '>' '{print $5,$9,$12}'|awk -F '[</]+' '{print $1,$2,$3}' |awk -F ' ' '{print $1,$3,$4,$NF}'
sleep 0.2
done
以下飞书登录
#!/bin/bash
whoip=`who am i |awk -F '[()]' '{print $2}'`
city=`curl -s https://ip.cn/index.php?ip=$whoip | grep 'id="tab0_address"' | cut -b 44-74 | sed s/[[:space:]]//g`
hostnam=`hostname`
ip=`ifconfig eth0|awk -F '[ :]+' 'NR==2 {print $3}'`
who=`whoami`
timers=`date '+%Y-%m-%d-%H:%M:%S'`
token="5607fcc9-34f4-4bff-9c32-22b01a295679"
usl="https://open.feishu.cn/open-apis/bot/v2/hook/5607fcc9-34f4-4bff-9c32-22b01a295679"
curl -X POST -H "Content-Type: application/json" \
-d '{"msg_type":"text","content":{"text":"主机IP: '$ip'\n登录用户: '$who'\n 登录IP: '$whoip'\n 登录时间:'$timers'\n 来自:'$city'"}}' $usl >/dev/null 2>/dev/null
exit 0