Skip to content

Commit

Permalink
Merge pull request #55 from RyosukeDTomita/feature/refactor-scan-class
Browse files Browse the repository at this point in the history
refactor Scan.py
  • Loading branch information
RyosukeDTomita authored Aug 30, 2024
2 parents 3a1f499 + 42430a2 commit 054677c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 0 additions & 2 deletions src/my_portscanner/scan_tools/ConnectScan.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# coding: utf-8
import socket
import asyncio
from dataclasses import dataclass
from .Scan import Scan


@dataclass
class ConnectScan(Scan):
def run(self) -> list[dict]:
"""_summary_
Expand Down
29 changes: 16 additions & 13 deletions src/my_portscanner/scan_tools/Scan.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
# coding: utf-8
from dataclasses import dataclass
import asyncio
from abc import abstractmethod
from abc import ABC, abstractmethod


@dataclass
class Scan:
class Scan(ABC):
# 初期化
target_ip: str
target_port_list: list[int]
max_rtt_timeout: int
max_parallelism: int
scan_result: list[dict]

def __init__(self, *args, **kwargs):
def __init__(self, target_ip: str, target_port_list: list[int], max_rtt_timeout: int, max_parallelism: int):
"""_summary_
継承専用のクラスのため,直接インスタンス化できないようにする。
Raises:
TypeError: _description_
constructor
Args:
target_ip str: target ip address
port_list list[int]: list of target port numbers
max_rtt_timeout int: max rtt timeout
max_parallelism int: max parallelism
"""
if type(self) is Scan:
raise TypeError(
"Scan is an abstract class and cannot be instantiated directly"
)
self.target_ip = target_ip
self.target_port_list = target_port_list
self.max_rtt_timeout = max_rtt_timeout
self.max_parallelism = max_parallelism
self.scan_result = []

def __str__(self) -> str:
"""_summary_
Expand Down
2 changes: 0 additions & 2 deletions src/my_portscanner/scan_tools/SynScan.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# coding: utf-8
from scapy.all import IP, TCP, sr1, conf
from dataclasses import dataclass
import asyncio
import sys
from .Scan import Scan


@dataclass
class SynScan(Scan):
def run(self) -> list[dict]:
"""
Expand Down

0 comments on commit 054677c

Please sign in to comment.