不修改vhosts通过python和shell实现一个域名解析到不同的ip
curl --resolve chinasoft.com:80:1.1.1.1 "http://chinasoft.com/"
完整示例:
cbs_servers="1.1.1.1:ws_cbs_frontend_web01 1.1.1.2:ws_cbs_frontend_web02"
for cbs_server in ${cbs_servers};do
ip=${cbs_server%:*}
server_name=${cbs_server#*:}
curl --head --resolve cbs.chinasoft.com:443:${ip} "https://cbs.chinasoft.com/"
if [ $? == 0 ];then
echo "${server_name}-${ip} is ok"
else
echo "${server_name}-${ip} config error"
exit 1
fi
done
python的实现方式
import requests
requests.get(‘https://192.168.1.10‘,headers={‘Host‘:‘chinasoft.com‘},verify=False)
或者
import urllib2
req=urllib2.Request(‘https://https://192.168.1.10‘,headers={‘Host‘:‘chinasoft.com‘})
urllib2.urlopen(req)
#urllib2 https会自动忽略证书
不修改vhosts通过python和shell实现一个域名解析到不同的ip
原文:https://www.cnblogs.com/reblue520/p/12989612.html