查找微信使用的IP地址:
1、 域名查找
# nslookup
> weixin.qq.com
Server:114.114.114.114
Address:114.114.114.114#53
Non-authoritative answer:
weixin.qq.comcanonical name = minorshort.weixin.qq.com.
Name:minorshort.weixin.qq.com
Address: 140.206.160.234
Name:minorshort.weixin.qq.com
Address: 140.207.54.47
Name:minorshort.weixin.qq.com
Address: 140.207.135.125
2、连接数查找
运行脚本: bash wechat.sh test 123456
多运行几次,查看是否有不同的IP
netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:33197 140.207.127.79:443 TIME_WAIT
tcp 0 0 0.0.0.0:33196 140.207.127.79:443 TIME_WAIT
3、 iptables 配置:
:OUTPUT DROP [8:1128]
-A OUTPUT -d 140.207.127.79/32 -p tcp -m tcp --dport 443 -j ACCEPT
-A OUTPUT -d 117.185.30.190/32 -p tcp -m tcp --dport 443 -j ACCEPT
-A OUTPUT -d 140.207.135.125/32 -p tcp -m tcp --dport 443 -j ACCEPT
-A OUTPUT -d 140.207.54.47/32 -p tcp -m tcp --dport 443 -j ACCEPT
-A OUTPUT -d 140.206.160.234/32 -p tcp -m tcp --dport 443 -j ACCEPT
-A OUTPUT -p udp -m udp --dport 53 -j ACCEPT
======================
bash 脚本:
[[email protected] alertscripts]# cat wechat.sh #!/bin/bash # Functions: send messages to wechat app # set variables CropID=‘xxxxxx‘ Secret=‘M3FMhnFh8nTI6SxLAEbbLLZaj-1BpZIyqkJRskeMMUXObGx4mfQsAg7Jw-nUMXe9‘ GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret" #get acccess_token Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F\" ‘{print $4}‘) PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken" # function body() { local int AppID=10 #企业号中的应用id local UserID="touser" #部门成员id,zabbix中定义的微信接收者 local PartyID=8 #部门id,定义了范围,组内成员都可接收到消息 local Msg=$(echo "[email protected]" | cut -d" " -f3-) #过滤出zabbix传递的第三个参数 printf ‘{\n‘ printf ‘\t"touser": "‘"$UserID"\"",\n" printf ‘\t"toparty": "‘"$PartyID"\"",\n" printf ‘\t"msgtype": "text",\n‘ printf ‘\t"agentid": "‘" $AppID "\"",\n" printf ‘\t"text": {\n‘ printf ‘\t\t"content": "‘"$Msg"\""\n" printf ‘\t},\n‘ printf ‘\t"safe":"0"\n‘ printf ‘}\n‘ } /usr/bin/curl --data-ascii "$(body $! $2 $3)" $PURL
#http://qydev.weixin.qq.com/wiki/index.php?title=消息类型及数据格式
#测试:
bash wechat.sh test hello.world! {"errcode":0,"errmsg":"ok","invaliduser":"all user invalid"}