mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Add Port Scanner Utility
This commit is contained in:
parent
2eadd24b8a
commit
692ded373d
8
Port_Scanner/README.md
Normal file
8
Port_Scanner/README.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Port Scanner
|
||||
A simple tool that asynchronously scans a server's ports with python. It's pretty quick as it processes ports in batches of 256.
|
||||
|
||||
## Required libraries
|
||||
None, the only libraries that are used are built-ins.
|
||||
|
||||
## Usage
|
||||
Use "port_scanner.py", and enter the IP that you want to scan when prompted.
|
40
Port_Scanner/port_scanner.py
Normal file
40
Port_Scanner/port_scanner.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
import asyncio
|
||||
from random import SystemRandom
|
||||
|
||||
def run(tasks, *, loop=None):
|
||||
"""Run Asynchronous Tasks"""
|
||||
if loop is None:
|
||||
loop = asyncio.get_event_loop()
|
||||
# waiting for all tasks
|
||||
return loop.run_until_complete(asyncio.wait(tasks))
|
||||
|
||||
async def scanner(ip, port, loop=None):
|
||||
fut = asyncio.open_connection(ip, port, loop=loop)
|
||||
|
||||
try:
|
||||
reader, writer = await asyncio.wait_for(fut, timeout=0.5) # This is where it is blocking?
|
||||
print("{}:{} Connected".format(ip, port))
|
||||
except asyncio.TimeoutError:
|
||||
pass
|
||||
# handle connection refused and bunch of others
|
||||
except Exception as exc:
|
||||
print('Error {}:{} {}'.format(ip, port, exc))
|
||||
|
||||
def scan(ips, ports, randomize=False):
|
||||
"""Scan the ports"""
|
||||
loop = asyncio.get_event_loop()
|
||||
if randomize:
|
||||
rdev = SystemRandom()
|
||||
ips = rdev.shuffle(ips)
|
||||
ports = rdev.shuffle(ports)
|
||||
|
||||
# let's pass list of task, not only one
|
||||
run([scanner(ip, port) for port in ports for ip in ips])
|
||||
|
||||
|
||||
ips = [input("IP to scan: ")]
|
||||
STEP = 256
|
||||
for r in range(STEP+1, 65536, STEP):
|
||||
# print(r)
|
||||
ports = [str(r) for r in list(range(r-STEP, r))]
|
||||
scan(ips, ports)
|
|
@ -48,6 +48,7 @@ So far, the following projects have been integrated to this repo:
|
|||
- [Colored B&W Image Converter](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Color_to_BW_Converter) by [Nitish Srivastava](https://github.com/nitish-iiitd)
|
||||
- [Gmail Mailing Script](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/mailing) by [mayank-kapur](https://github.com/kapurm17)
|
||||
- [Take Screenshot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Take_screenshot) by [Moad Mohammed Elhebri](https://github.com/moadmmh)
|
||||
- [Port Scanner](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Port_Scanner) by [Plutoberth](https://github.com/Plutoberth)
|
||||
|
||||
## Contribuition Guidelines :
|
||||
- Make a Seperate Folder for the Script.
|
||||
|
|
Loading…
Reference in New Issue
Block a user