testIPType.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 r.text
  14. # if r.ok:
  15. # root = etree.HTML(r.text)
  16. # ip = root.xpath('.//center[2]/table/tr[3]/td[2]')[0].text
  17. # http_x_forwared_for = root.xpath('.//center[2]/table/tr[8]/td[2]')[0].text
  18. # http_via = root.xpath('.//center[2]/table/tr[9]/td[2]')[0].text
  19. # # print ip,http_x_forwared_for,http_via,type(http_via),type(http_x_forwared_for)
  20. # if ip==selfip:
  21. # return 3
  22. # if http_x_forwared_for is None and http_via is None:
  23. # return 0
  24. # if http_via != None and http_x_forwared_for.find(selfip)== -1:
  25. # return 1
  26. #
  27. # if http_via != None and http_x_forwared_for.find(selfip)!= -1:
  28. # return 2
  29. # return 3
  30. except Exception,e:
  31. print str(e)
  32. return 3
  33. if __name__=='__main__':
  34. ip = '61.132.241.109'
  35. port = '808'
  36. proxies={"http": "http://%s:%s"%(ip,port),"https": "http://%s:%s"%(ip,port)}
  37. checkProxyType(None,proxies)