Skip to content

Commit

Permalink
Optimized the code for handling erros and stoping the scan
Browse files Browse the repository at this point in the history
  • Loading branch information
rionislam committed Jan 14, 2024
1 parent 3aa565f commit f88acc8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# BDIX Tester

[![Version](https://img.shields.io/badge/version-1.0.1-blue.svg)](https://github.com/rionislam/BDIX-Tester/releases/tag/v1.0.1)

Check the available BDIX Ftp servers for you easily

## Use
Expand All @@ -22,3 +24,5 @@ Check the available BDIX Ftp servers for you easily
```

- Just wait and you will see the avaible servers for you.

- Press **CTRL**+**C** to stop the scanning
35 changes: 22 additions & 13 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@

file = open("targets.json")
targets = json.load(file)
length = len(targets["hosts"])
for i in range(0, length):
host = targets["hosts"][i]
try:
response = requests.get(host, timeout=1)
status = response.status_code
except:
status = 'error'
file.close()

try:
for host in targets.get("hosts", []):
try:
response = requests.get(host, timeout=1)
response.raise_for_status()
status = response.status_code
except requests.exceptions.RequestException as e:
status = 'error'

continue

if status == 200:
time = response.elapsed.total_seconds()
size = len(response.content)
speed = (size * 8) / (time * 1000000)
print(f"Host: {host} AND Speed: {speed:.2f} Mbps\n")

response.close()
if status == 200:
time = response.elapsed.total_seconds()/1000
size = (((len(response.text))/1000000)/8)/8
speed = size/time
print (f"Host: {host} AND Speed: {format(speed, '.2f') }MBps\n")

except KeyboardInterrupt:
print("\nScript terminated by user (Ctrl+C).")

0 comments on commit f88acc8

Please sign in to comment.