{"id":19830014,"url":"https://github.com/2003harsh/port-scanner-from-scratch-using-python","last_synced_at":"2026-05-25T16:35:18.156Z","repository":{"id":249263933,"uuid":"831015857","full_name":"2003HARSH/Port-Scanner-from-scratch-using-python","owner":"2003HARSH","description":"A Python-based port scanner that identifies open ports and gathers service information. It resolves IP addresses and hostnames, performs banner grabbing, and can scan multiple targets for educational and network security purposes.","archived":false,"fork":false,"pushed_at":"2024-07-19T13:42:23.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-23T19:04:34.374Z","etag":null,"topics":["cyber-security","port-scanner","python3","socket-programming"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2003HARSH.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-19T13:16:53.000Z","updated_at":"2024-07-19T13:42:27.000Z","dependencies_parsed_at":"2024-07-19T19:01:24.649Z","dependency_job_id":null,"html_url":"https://github.com/2003HARSH/Port-Scanner-from-scratch-using-python","commit_stats":null,"previous_names":["2003harsh/port-scanner-from-scratch-using-python"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/2003HARSH/Port-Scanner-from-scratch-using-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2003HARSH%2FPort-Scanner-from-scratch-using-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2003HARSH%2FPort-Scanner-from-scratch-using-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2003HARSH%2FPort-Scanner-from-scratch-using-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2003HARSH%2FPort-Scanner-from-scratch-using-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2003HARSH","download_url":"https://codeload.github.com/2003HARSH/Port-Scanner-from-scratch-using-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2003HARSH%2FPort-Scanner-from-scratch-using-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33484331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-25T14:31:05.219Z","status":"ssl_error","status_checked_at":"2026-05-25T14:31:02.878Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cyber-security","port-scanner","python3","socket-programming"],"created_at":"2024-11-12T11:21:16.602Z","updated_at":"2026-05-25T16:35:18.125Z","avatar_url":"https://github.com/2003HARSH.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Port Scanner from scratch using Python\n\nThis Python script is a simple yet effective port scanner that allows you to check for open ports on a specified target. The script resolves both IP addresses and hostnames, performs banner grabbing to gather information about the services running on open ports, and can scan a range of ports for multiple targets.\n\n## Features\n\n- Resolves IP addresses and hostnames.\n- Scans a range of ports for open ports.\n- Performs banner grabbing to gather information about services running on open ports.\n- Allows scanning of multiple targets.\n\n## Requirements\n\n- Python 3.x\n- IPy module (`pip install IPy`)\n\n## Usage\n\n### As a Script\n\n1. Save the script as `portscanner.py`.\n2. Run the script from the command line:\n\n```bash\npython portscanner.py\n```\n\n3. Enter the target(s) to scan when prompted. Separate multiple targets with spaces.\n\n```plaintext\n[+] Enter target/s to scan (separate targets with space): example.com 192.168.1.1\n```\n\n## Code Explanation\n\n### Import Libraries\n\n```python\nfrom IPy import IP\nimport socket\n```\n\n### Check IP or Resolve Hostname\n\n```python\ndef check_ip(ip):\n    try:\n        IP(ip)\n        return ip\n    except ValueError:\n        return socket.gethostbyname(ip)\n```\n\n- `check_ip(ip)`: Checks if the input is an IP address. If not, it resolves the hostname to an IP address.\n\n### Banner Grabbing\n\n```python\ndef get_banner(s):\n    return s.recv(1024)\n```\n\n- `get_banner(s)`: Receives up to 1024 bytes of data from the socket to gather service information.\n\n### Scan a Specific Port\n\n```python\ndef scan_port(ipaddr, port):\n    try:\n        sock = socket.socket()\n        sock.settimeout(0.5)\n        sock.connect((ipaddr, port))\n        try:\n            banner = get_banner(sock)\n            print(\"[+] Open Port \" + str(port) + \" : \" + str(banner.decode()))\n        except:\n            print(\"[+] Open Port \" + str(port))\n    except:\n        pass\n```\n\n- `scan_port(ipaddr, port)`: Tries to connect to the specified port. If successful, it attempts to grab the banner and print information about the service.\n\n### Scan a Range of Ports on a Target\n\n```python\ndef scan(target):\n    converted_ip = check_ip(target)\n    for port in range(1, 1000):\n        scan_port(converted_ip, port)\n```\n\n- `scan(target)`: Scans ports 1 to 999 on the given target.\n\n### Main Function\n\n```python\nif __name__ == \"__main__\":\n    targets = input(\"[+] Enter target/s to scan (separate targets with space) \")\n    for ipaddr in targets.split(\" \"):\n        converted_ip = check_ip(ipaddr)\n        print(\"[ 0 - Scanning ] \" + str(ipaddr))\n        for port in range(1, 85):\n            scan_port(converted_ip, port)\n```\n\n- When run directly, the script prompts for targets, resolves them, and scans ports 1 to 84 on each target.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2003harsh%2Fport-scanner-from-scratch-using-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2003harsh%2Fport-scanner-from-scratch-using-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2003harsh%2Fport-scanner-from-scratch-using-python/lists"}