Skip to content

Instantly share code, notes, and snippets.

@NKUCodingCat
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NKUCodingCat/f70b9fd9d958ea5fad80 to your computer and use it in GitHub Desktop.
Save NKUCodingCat/f70b9fd9d958ea5fad80 to your computer and use it in GitHub Desktop.
#coding=utf-8
import socket
import ssl
import os
import platform
import random
import re
import IPy
socket_timeout = 10.0
ssl_timeout = 10.0
root = os.path.split(os.path.realpath(__file__))[0]+"/"
RxResult = re.compile("""^(HTTP/... (\d+).*|Server:\s*(\w.*))$""", re.IGNORECASE|re.MULTILINE)
def Par_res(String):
try:
Arr = RxResult.findall(String)
status = "NN"
for i in Arr:
if i[1] == "200":
for j in Arr:
if j[2] == "gws\r":
status = "GA"
elif j[2] == "Google Frontend\r":
status = "A"
else:
pass
except:
return None
if status == "NN":
return None
else:
return status
def SSL_Test(ip):
"""
if this ip is available as GAE ip, the func will return like: {"ip": ip, "cname": CName, "Status": status}
if not , return None
"""
try:
if IPy.IP(ip).version() == 4:
s = socket.socket()
elif IPy.IP(ip).version() == 6:
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM, 0)
else:
print "There is an invalid string in SSL_Test Func:",ip
return None
except KeyboardInterrupt:
raise
except:
#raise
return None
try: #Gernel
s.settimeout(socket_timeout)
c = ssl.wrap_socket(s, cert_reqs=ssl.CERT_REQUIRED, ca_certs=root+'cacert.pem', ciphers='ECDHE-RSA-AES128-SHA')
c.settimeout(ssl_timeout)
c.connect((ip, 443))
cert = c.getpeercert()
c.write("HEAD /search?q=g HTTP/1.1\r\nHost: www.google.com.hk\r\n\r\nGET /%s HTTP/1.1\r\nHost: azzvxgoagent%s.appspot.com\r\nConnection: close\r\n\r\n"%(platform.python_version() , random.randrange(7)))
res = c.read(2048)
Cer = [j for j in [i[0] for i in cert["subject"]] if j[0] == "commonName"][0][1]
status = Par_res(res)
print "SSL Test in ", ip, "Cert is ", Cer
print res
except KeyboardInterrupt:
raise
except:
#raise
return None
if status:
return {"ip": ip, "cname": Cer, "Status": status}
else:
return None
if __name__ == "__main__":
ippool = ["139.175.107.136","139.175.107.155","139.175.107.213","210.242.125.79","139.175.107.219","139.175.107.41","116.92.194.157","139.175.107.239","139.175.107.169","139.175.107.146","210.242.125.83","139.175.107.132","139.175.107.224","116.92.194.186","210.242.125.42","203.165.13.202","139.175.107.208","139.175.107.76","163.28.83.132","139.175.107.244","139.175.107.214","103.1.139.180","139.175.107.175","210.242.125.11","223.26.69.25","139.175.107.74","116.92.194.171","210.242.125.97","223.26.69.44","223.26.69.19","210.242.125.77","223.26.69.12","139.175.107.180"]
for i in ippool:
SSL_Test(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment