Hack Forums
[The Brotherhood] Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Hacks, Exploits, and Various Discussions (https://hackforums.net/forumdisplay.php?fid=45)
+--- Forum: Whitehat • Blue Team • Defensive Security (https://hackforums.net/forumdisplay.php?fid=448)
+---- Forum: Pentesting and Forensics (https://hackforums.net/forumdisplay.php?fid=231)
+---- Thread: [The Brotherhood] Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code (/showthread.php?tid=6266469)

Pages: Pages 1 2


Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - Hackers - Mar 21, 2024

PSCAN.EXE
Your portable IP scanning tool


[Image: pscan-banner.png]



[Image: header4.gif]

Pscan is a small utility tool that can scan for open ports on any IP address. You can look for some common, default ports, or you can enter your own range to search for.

[Image: Screenshot-2024-03-21-084325.png]



Download the Program
Choose 1 link
Code
https://mega.nz/file/wnEiFaSQ#YnMdbi6ZwyJPQ1vNNBNPZmGOCaLBIkOCU0VLRLDiijw
https://www.mediafire.com/file/7scst8scv7cfdii/Pscan-Python-v0.0.1-nodes.exe/file

This is my first time using Pyinstaller for a release like this in years, so please let me know if you have any issues with it working.



Get the sauce!
Code
import socket

def is_port_open(ip, port):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(1)  # Timeout of 1 second
    try:
        sock.connect((ip, port))
    except socket.error:
        return False
    return True

def scan_ports(ip, mode='common', min_port=1, max_port=65535, common_ports=[21, 22, 23, 25, 80, 110, 443]):
    open_ports = []
    if mode == 'r':
        # Scan the specified range of ports
        for port in range(min_port, max_port + 1):
            if is_port_open(ip, port):
                open_ports.append(port)
    else:
        # Scan common ports
        for port in common_ports:
            if is_port_open(ip, port):
                open_ports.append(port)
    return open_ports

# Example usage
if __name__ == "__main__":
    end = False
    while(end == False):
        target_ip = input("Enter IP address to scan (or enter Q to quit): ")
        if(target_ip == "Q" or target_ip == "q"):
            end = True
            break
        mode = input("Enter scan mode ('d' or 'r'). Type in d (default / common ports) or r (range), press enter): ").lower()
        if mode == 'r':
            min_port = int(input("Enter minimum port number: "))
            max_port = int(input("Enter maximum port number: "))
            print(f"Scanning range {min_port}-{max_port}...")
            open_ports = scan_ports(target_ip, mode, min_port, max_port)
        elif(mode == "Q" or mode == "q"):
            end = True
            break
        else:
            print("Scanning common ports...")
            open_ports = scan_ports(target_ip)
        print("Open ports:", open_ports)
        print("\n\n\n")



Compile It!
To compile into an exe program, you can use Pyinstaller:
Code
pyinstaller --onefile pscan.py

Just run that command from the same directory as your file and it will convert it to a Windows program in the following relative path (or similar):
Code
dist/Pscan.exe



Deja Vu?
There are two versions of Pscan originally: the C++ version, and the Python (using Pyinstaller) version.

The Python version, for this release in this thread, was modified from the original to include a loop (to scan more than 1 IP per terminal session) and the addition of the 'Q' entry to quit the program.

If you want to learn more about how they work or make your own custom program, check out the original port scanning hacking tutorial.


RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - terrytickle - Mar 21, 2024

So, I used this, and found [22] ports.

But it didn't tell me what they were? Is this not pretty useless? lol


RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - Hackers - Mar 21, 2024

(Mar 21, 2024 10:42 AM)terrytickle Wrote:  So, I used this, and found [22] ports.

But it didn't tell me what they were? Is this not pretty useless? lol

This is your first post on the forum? Pretty ballsy to be calling something useless? lol

You are seeing the response that port 22 is open.
Open Ports: [22]
that means there is 1 port open, and 22 is the port.


[Image: Screenshot-2024-03-21-134624.png]

Usually I try to be as nice as possible to new users, but your first post calling my software useless and being incorrect is not a great first impression...


RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - so9or - Mar 21, 2024

so nice buddy , there are many errors in your programming


RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - Hackers - Mar 21, 2024

(Mar 21, 2024 03:59 PM)so9or Wrote:  so nice buddy , there are many errors in your programming

I put a disclaimer saying this.I don't usually use pyinstaller.So if you have any problems just put the bugs here and I'll get them fixed thanks


RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - terrytickle - Mar 23, 2024

[quote="nodes" pid='62309883' dateline='1711043264']

Sorry. I assumed your program was telling me 22 ports were open.

Maybe you should change it, to output:


Found Ports: X
Port: [22], [55], etc?

Because I thought you found 22 open ports, but didn't tell me what they were. My bad.


RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - ℛedemption - Mar 23, 2024

(Mar 23, 2024 08:39 AM)terrytickle Wrote:  [quote="nodes" pid='62309883' dateline='1711043264']

Sorry. I assumed your program was telling me 22 ports were open.

Maybe you should change it, to output:


Found Ports: X
Port: [22], [55], etc?

Because I thought you found 22 open ports, but didn't tell me what they were. My bad.

The output doesn't need changing, it does exactly what it's supposed to do. I'm not trying to be rude, but based on this post and your previous one, it's pretty clear you're unfamiliar with ports. Here's a fairly short YouTube video that explains what ports are, and how they work. Once you know what ports are, the output of the script is easy to understand.


RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - terrytickle - Mar 23, 2024

Not really.

I know what a port is, and I was expecting more than one port to be open from a large search I did with this tool.

So when the output was

Opened Ports: [22] , I assumed your script broke and didn't show me the actual open ports.

Since you had no other replies on your thread, it looks like a brand new script and noone else has tried it.


Adding an extra line of code:

A total of X ports were found open:
[22]

would be much better.

KIND REGARDS


RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - Hackers - Mar 23, 2024

(Mar 23, 2024 09:25 AM)terrytickle Wrote:  Not really.

I know what a port is, and I was expecting more than one port to be open from a large search I did with this tool.

So when the output was

Opened Ports: [22] , I assumed your script broke and didn't show me the actual open ports.

Since you had no other replies on your thread, it looks like a brand new script and noone else has tried it.


Adding an extra line of code:

A total of X ports were found open:
[22]

would be much better.

KIND REGARDS

I understand what you are saying.
The reason for [ ] is because that's an array, so usually it says Open Ports: [22, 80, 443] --- it's more apparent when there is more than 1.
If I do another release I'll add this in, otherwise just write a line like this one to say the number of ports w/ the length of the open_ports list.
Code
print("Open ports:", open_ports)



RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - G.P.D. - Apr 27, 2024

Hi OP, thank you for sharing your script

While I prefer to use nmap for port scanning, I appreciate the hands-on coding experience your script provides

I'd like to give some feedback: the one-second delay between scanning each port really impacts the duration of a scan, especially for a wide range (e.g. 20 to 4444). You might consider using futures for parallel execution to enhance efficiency.

Here is an example of how you could implement this:

Code
import socket
import concurrent.futures

def is_port_open(ip, port):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(1)
    try:
        sock.connect((ip, port))
    except socket.error:
        return False
    return True

def scan_ports(ip, mode='common', min_port=1, max_port=65535, common_ports=[21, 22, 23, 25, 80, 110, 443]):
    open_ports = []
    if mode == 'r':
        with concurrent.futures.ThreadPoolExecutor() as executor:
            port_range = range(min_port, max_port + 1)
            results = [executor.submit(is_port_open, ip, port) for port in port_range]
            for future in concurrent.futures.as_completed(results):
                if future.result():
                    open_ports.append(future.result())
    else:
        with concurrent.futures.ThreadPoolExecutor() as executor:
            results = [executor.submit(is_port_open, ip, port) for port in common_ports]
            for future in concurrent.futures.as_completed(results):
                if future.result():
                    open_ports.append(future.result())
    return open_ports

if __name__ == "__main__":
    end = False
    while(end == False):
        target_ip = input("Enter IP address to scan (or enter Q to quit): ")
        if(target_ip == "Q" or target_ip == "q"):
            end = True
            break
        mode = input("Enter scan mode ('d' or 'r'). Type in d (default / common ports) or r (range), press enter): ").lower()
        if mode == 'r':
            min_port = int(input("Enter minimum port number: "))
            max_port = int(input("Enter maximum port number: "))
            print(f"Scanning range {min_port}-{max_port}...")
            open_ports = scan_ports(target_ip, mode, min_port, max_port)
        elif(mode == "Q" or mode == "q"):
            end = True
            break
        else:
            print("Scanning common ports...")
            open_ports = scan_ports(target_ip)
        print("Open ports:", open_ports)
        print("\n\n\n")



RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - Hackers - Apr 28, 2024

(Apr 27, 2024 03:58 AM)G.P.D. Wrote:  Hi OP, thank you for sharing your script

While I prefer to use nmap for port scanning, I appreciate the hands-on coding experience your script provides

I'd like to give some feedback: the one-second delay between scanning each port really impacts the duration of a scan, especially for a wide range (e.g. 20 to 4444). You might consider using futures for parallel execution to enhance efficiency.

thanks, this is really good to look into. The big ranges are definitely impacted. I'm going to rethink this and see what I can do to release a new version. Good point - cheers!


RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - thebigboss - Apr 30, 2024

Very useful! Thanks for sharing


RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - Hackers - Apr 30, 2024

(Apr 30, 2024 03:46 AM)thebigboss Wrote:  Very useful! Thanks for sharing

No problem, glad you like it !


RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - Vagabundo Legendario - Jul 12, 2024

(Mar 21, 2024 10:42 AM)terrytickle Wrote:  So, I used this, and found [22] ports.

But it didn't tell me what they were? Is this not pretty useless? lol

the earth is not flat man


RE: Pscan.exe ~ IP Address Port Scanner ~ Ready to Use Program + Source Code - longchen_1562 - Jul 15, 2024

Can you help me with web research?