Skip to content

Instantly share code, notes, and snippets.

@this-is-r-gaurav
Created January 25, 2019 13:56
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 this-is-r-gaurav/7a9e392e8f490b447db3c10e89380984 to your computer and use it in GitHub Desktop.
Save this-is-r-gaurav/7a9e392e8f490b447db3c10e89380984 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import nmap
from scrapy.exceptions import DropItem
nm = nmap.PortScanner()
class ProxyPipeline(object):
def process_item(self, item, spider):
if 'ip' in item.keys():
res = nm.scan(item['ip'], item['port'])
hosts = nm.all_hosts()
if hosts:
protocols = nm[hosts[0]].all_protocols()
ports = list(nm[hosts[0]][protocols[0]].keys())
status =nm[hosts[0]][protocols[0]][ports[0]]['state']
if status != "closed":
return item
else:
raise DropItem("Proxy isn't UP")
else:
raise DropItem("Proxy isn't UP")
else:
return item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment