black format

This commit is contained in:
Heath Brown
2022-11-01 11:40:52 -05:00
parent c6cd5b270f
commit 1ce01ace73
6 changed files with 28 additions and 16 deletions

View File

@@ -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"

View File

@@ -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
def is_port_open(host: str, port: int) -> bool:
try:
s = socket.socket()
@@ -31,12 +34,14 @@ 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")

View File

@@ -3,7 +3,7 @@
# SPDX-License-Identifier: MIT
import sys
if __name__ == '__main__':
if __name__ == "__main__":
from .cli import pscanner
sys.exit(pscanner())

View File

@@ -6,10 +6,13 @@ 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):

View File

@@ -25,6 +25,7 @@ classifiers = [
]
dependencies = [
"click",
"pythonping"
]
dynamic = ["version"]

View File

@@ -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