Banner grabbing Pycharm + terminal

Hello everyone 

As new learner I'm encountering this issue : 

When I try (following the RedCode lessons) to perform a banner grabbing on the terminal, I get this message :

 

C:\Users\xxxxx\AppData\Local\Microsoft\WindowsApps\python3.exe: can't open file 'C:\\Users\\xxxx\\PycharmProjects\\pythonProject\\python_port_scanner_banner.py': [Errno 2] No such file or directory

What I use ine the terminal is : python3 python_port_scanner_banner.py -o 192.168.1.39 -p 139,112,512,514,1099
(IP Address is from Metasploitable)
Could someone helmp me to understand why I get this, however the teacher get a normal answer with the versions and not me?

 

In advance, thank you very much !

The main code I use is : 

import argparse
import socket
import threading


def connection_scan(target_ip, target_port):
try:
conn_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn_socket.connect((target_ip, target_port))
conn_socket.send(b'Banner_query\r\n')
results = conn_socket.recv(100)
print("[+] {}/tcp open".format(target_port))
print("[+] {}".format(str(results)))
except OSError:
print("[-] {}/tcp closed".format(target_port))
finally:
conn_socket.close()


def port_scn(target, port_num):
try:
target_ip = socket.gethostbyname(target)
except OSError:
print("[^] Cannot resolve {}: Unknown host".format(target))
return

try:
target_name = socket.gethostbyname(target_ip)
print('[*] Scan Results for: {}'.format(target_name[0]))
except OSError:
print('[*] Scan Results for: {}'.format(target_ip))

t = threading.Thread(target=connection_scan, args=(target, int(port_num)))
t.start()


def argument_parser():
parser = argparse.ArgumentParser(description="TCP port scanner. Accepts a hostname/IP address and list of ports to "
"scan. Attempts to identify the service running on a port.")
parser.add_argument("-o", "--host", nargs="?", help="Host IP address")
parser.add_argument("-p", "--port", nargs="?", help="Comma-separated port list, such as '25,80.8080'")

var_args = vars(parser.parse_args())

return var_args


if __name__ == '__main__':
try:
user_args = argument_parser()
host = user_args["host"]
port_list = user_args["port"].split(",")
for port in port_list:
port_scn(host, port)
except AttributeError:
print("Error. Please provide the command-line arguments before running")
0

This error means the file does not exist in your current working directory. Please run `dir` and make sure the file is there. 

To solve the issue, you can either navigate to the correct working directory, or use the absolute path to run the file.

0

请先登录再写评论。