testIPType.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # coding:utf-8
  2. from lxml import etree
  3. import requests
  4. import config
  5. def checkProxyType(selfip, proxies):
  6. '''
  7. 用来检测代理的类型,突然发现,免费网站写的信息不靠谱,还是要自己检测代理的类型
  8. :param proxies: 代理(0 高匿,1 匿名,2 透明 3 无效代理
  9. :return:
  10. '''
  11. try:
  12. r = requests.get(url='https://incloak.com/ip/', headers=config.HEADER, timeout=config.TIMEOUT, proxies=proxies)
  13. print
  14. r.text
  15. # if r.ok:
  16. # root = etree.HTML(r.text)
  17. # ip = root.xpath('.//center[2]/table/tr[3]/td[2]')[0].text
  18. # http_x_forwared_for = root.xpath('.//center[2]/table/tr[8]/td[2]')[0].text
  19. # http_via = root.xpath('.//center[2]/table/tr[9]/td[2]')[0].text
  20. # # print ip,http_x_forwared_for,http_via,type(http_via),type(http_x_forwared_for)
  21. # if ip==selfip:
  22. # return 3
  23. # if http_x_forwared_for is None and http_via is None:
  24. # return 0
  25. # if http_via != None and http_x_forwared_for.find(selfip)== -1:
  26. # return 1
  27. #
  28. # if http_via != None and http_x_forwared_for.find(selfip)!= -1:
  29. # return 2
  30. # return 3
  31. except Exception as e:
  32. print
  33. str(e)
  34. return 3
  35. if __name__ == '__main__':
  36. ip = '61.132.241.109'
  37. port = '808'
  38. proxies = {"http": "http://%s:%s" % (ip, port), "https": "http://%s:%s" % (ip, port)}
  39. checkProxyType(None, proxies)