black format
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2022-present U.N. Owen <void@some.where>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
__version__ = '0.0.1'
|
||||
__version__ = "0.0.1"
|
||||
|
||||
@@ -12,12 +12,15 @@ GREEN = Fore.GREEN
|
||||
RESET = Fore.RESET
|
||||
GRAY = Fore.LIGHTBLACK_EX
|
||||
|
||||
|
||||
def is_host_alive(host: str) -> bool:
|
||||
if ping(host, timeout=1, count=1).success():
|
||||
return True
|
||||
else:
|
||||
print(f"{GRAY}{host:15} is not alive {RESET}")
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
def is_port_open(host: str, port: int) -> bool:
|
||||
try:
|
||||
s = socket.socket()
|
||||
@@ -31,14 +34,16 @@ def is_port_open(host: str, port: int) -> bool:
|
||||
finally:
|
||||
s.close()
|
||||
|
||||
|
||||
def is_subnet(ip: str) -> bool:
|
||||
if '/' in ip:
|
||||
if "/" in ip:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def hosts_in_subnet(network: str) -> List:
|
||||
if not is_subnet:
|
||||
print(f"{network} is not a network")
|
||||
|
||||
return list(ipaddress.ip_network(network).hosts())
|
||||
|
||||
return list(ipaddress.ip_network(network).hosts())
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
import sys
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
from .cli import pscanner
|
||||
|
||||
sys.exit(pscanner())
|
||||
|
||||
@@ -6,16 +6,19 @@ from pscanner import is_port_open, is_subnet, hosts_in_subnet, is_host_alive
|
||||
from ..__about__ import __version__
|
||||
|
||||
|
||||
@click.group(context_settings={'help_option_names': ['-h', '--help']}, invoke_without_command=True)
|
||||
@click.version_option(version=__version__, prog_name='pscanner')
|
||||
@click.argument('host')
|
||||
@click.argument('port')
|
||||
@click.group(
|
||||
context_settings={"help_option_names": ["-h", "--help"]},
|
||||
invoke_without_command=True,
|
||||
)
|
||||
@click.version_option(version=__version__, prog_name="pscanner")
|
||||
@click.argument("host")
|
||||
@click.argument("port")
|
||||
@click.pass_context
|
||||
def pscanner(ctx: click.Context, host, port):
|
||||
if is_subnet(host):
|
||||
for ip in hosts_in_subnet(host):
|
||||
if is_host_alive(str(ip)):
|
||||
is_port_open(str(ip), port)
|
||||
else:
|
||||
if is_host_alive(host):
|
||||
is_port_open(host, port)
|
||||
else:
|
||||
if is_host_alive(host):
|
||||
is_port_open(host, port)
|
||||
|
||||
@@ -25,6 +25,7 @@ classifiers = [
|
||||
]
|
||||
dependencies = [
|
||||
"click",
|
||||
"pythonping"
|
||||
]
|
||||
dynamic = ["version"]
|
||||
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import pscanner
|
||||
import pytest
|
||||
|
||||
|
||||
def test_is_port_open():
|
||||
pass
|
||||
|
||||
|
||||
def test_is_subnet():
|
||||
assert pscanner.is_subnet('192.168.1.0') == False
|
||||
assert pscanner.is_subnet('192.168.0/24') == True
|
||||
assert pscanner.is_subnet("192.168.1.0") == False
|
||||
assert pscanner.is_subnet("192.168.0/24") == True
|
||||
|
||||
|
||||
def test_hosts_in_subnet():
|
||||
assert len(pscanner.hosts_in_subnet('192.168.0.0/29')) == 6
|
||||
assert len(pscanner.hosts_in_subnet("192.168.0.0/29")) == 6
|
||||
|
||||
Reference in New Issue
Block a user