Skip to content

Commit

Permalink
Added ThreadSafe Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaeem20 committed Jan 13, 2022
1 parent 8c11832 commit af9b36d
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions webeye/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def reversedns(host: str) -> str:
api = requests.get(f'https://api.hackertarget.com/reversedns/?q={realip}').text.strip(f'{realip} ')
return api

def scan(target: str, port: Union[int, Iterable], start: int=0, dev_mode: bool=False, api :bool=False) -> Union[tuple,None]:
def scan(target: str, port: Union[int, Iterable], start: int=0, dev_mode: bool=False, api :bool=False, threads: int=100) -> Union[tuple,None]:
'''Python Port Scanner Enumerate all Open Ports of Given Host:\n
Use dev_mode = True, if You want response in list.\n
Use API = True if you are making api
Expand All @@ -84,11 +84,11 @@ def scan_port(port) -> Union[str,list]:
elif api:
lists.append(f'{port}/tcp | {socket.getservbyport(port)}')
else:
print(f'{port}/tcp\t | {socket.getservbyport(port)}\t| open |')
print(f'{port}/tcp\t | {socket.getservbyport(port)}\t| open |')
sock.close()

def execute():
with ThreadPoolExecutor(max_workers=10000) as host:
with ThreadPoolExecutor(max_workers=threads) as host:
if isinstance(port, Iterable):
host.map(scan_port, port)
return 'Scan Finished.'
Expand All @@ -115,7 +115,7 @@ def execute():
return sys.exit('Process Stopped Exiting: 1')

def subenum(host: str, cli=False, no_ip=True) -> Union[list, dict, None]:
"""Enumerate a list of subdomains for given host Asynchronously"""
"""Enumerate a list of subdomains for given host"""
try:
GLOBAL_LIST = []
api = requests.get(f"https://api.hackertarget.com/hostsearch/?q={host}")
Expand Down Expand Up @@ -146,8 +146,6 @@ def subenum(host: str, cli=False, no_ip=True) -> Union[list, dict, None]:

except requests.ConnectionError:
return 'Connection Lost: Retry Again'
except requests.ConnectTimeout:
return 'Taking too long! Exiting: 1'
except KeyboardInterrupt:
return sys.exit('Stopped, Exiting: 1')

Expand All @@ -173,8 +171,6 @@ def grab(host: str, schema='http://', cli=False) -> Union[dict, None]:
return dict(api.headers)
except requests.ConnectionError:
return 'Connection Lost: Exiting...'
except requests.ConnectTimeout:
return 'Unable to Get Response'
except KeyboardInterrupt:
return sys.exit('Stopped, Exiting: 1')

Expand Down Expand Up @@ -250,8 +246,6 @@ def is_cloudflare(host: str, schema='http://', cli=False) -> Union[bool, None]:
return False
except requests.ConnectionError:
return 'Connection Lost: Exiting...'
except requests.ConnectTimeout:
return 'Unable to Get Response'
except KeyboardInterrupt:
return sys.exit('Stopped, Exiting: 1')

Expand All @@ -266,8 +260,6 @@ def fetch_dns(host: str, cli=False) -> Union[None, list]:
return result
except requests.ConnectionError:
return 'Connection Lost: Exiting...'
except requests.ConnectTimeout:
return 'Unable to Get Response'
except KeyboardInterrupt:
return sys.exit('Stopped, Exiting: 1')

Expand All @@ -278,8 +270,6 @@ def isitdown(host: str) -> dict:
return response
except requests.ConnectionError:
return 'Connection Lost: Exiting...'
except requests.ConnectTimeout:
return 'Unable to Get Response'
except KeyboardInterrupt:
return sys.exit('Stopped, Exiting: 1')

Expand Down Expand Up @@ -360,7 +350,7 @@ async def reversedns(self, hostip: str) -> str:
else:
return 'Enter IP of Host not URL'

async def scan(self, target: str, port: Union[int, Iterable], start: int=0, dev_mode: bool=False, api :bool=False) -> Union[list, None]:
async def scan(self, target: str, port: Union[int, Iterable], start: int=0, dev_mode: bool=False, api :bool=False, threads: int=100) -> Union[list, None]:
'''Asynchronous Python Port Scanner Enumerate all Open Ports of Given Host:\n
Use dev_mode = True, if You want response in list.\n
Use API = True if you are making api
Expand All @@ -379,11 +369,11 @@ def scan_port(port) -> Union[None,list]:
elif api:
lists.append(f'OPEN_PORTS | {port}tcp/{socket.getservbyport(port)}')
else:
print(f'{port}/tcp\t | {socket.getservbyport(port)}\t| open |')
print(f'{port}/tcp\t | {socket.getservbyport(port)}\t| open |')
sock.close()

async def execute():
with ThreadPoolExecutor(max_workers=10000) as host:
with ThreadPoolExecutor(max_workers=threads) as host:
if isinstance(port, Iterable):
host.map(scan_port, port)
return 'Scan Finished.'
Expand Down Expand Up @@ -428,9 +418,9 @@ async def find_subdomains(self,host: str, cli=False, no_ip=True) -> Union[list,
cliresponse.append(x.split(','))
for i,v in enumerate(cliresponse, start=1):
if no_ip:
print(f'{i}). {v}')
print(f'{i:02}). {v}')
else:
print(f"{v[0].ljust(60,' ')} | {v[1].rjust(40,' ')} << ({i})")
print(f"{v[0].ljust(60,' ')} | {v[1].rjust(40,' ')} << ({i:02})")
else:
if no_ip:
return list(line.split(',')[0] for line in lines)
Expand Down Expand Up @@ -586,4 +576,4 @@ async def is_honeypot(self, host: str, score: bool=False) -> Union[float, None]:
except socket.error:
return f'{socket.gethostbyname(host)} is Unreachable'
except KeyboardInterrupt:
return sys.exit('Stopped, Exiting: 1')
return sys.exit('Stopped, Exiting: 1')

0 comments on commit af9b36d

Please sign in to comment.