in Education by
This is my code it's just starting the scan but it is not completing ,where is the error in it. i need output as port number and port side by side.when i run in command prompt it gives like that,please give suggetions on that from socket import * import sys,time from datetime import datetime host ='' max_port=100 min_port=1 def scan_host(host,port,r_code=1): try: s=socket(AF_INET,SOCK_STREAM) code=s.connect_ex((host,port)) if code==0: r_code=code s.close() except Exception,e: pass return r_code try: host=raw_input("Enter Host address:") except KeyboardInterrupt: print("\n Application shtdown") sys.exit(1) hostip=gethostbyname(host) print("\n Host:%s IP:%s" %(host,hostip)) print("Scanning Started At %s...\n" %(time.strftime("%H:%M:%S"))) start_time=datetime.now() for port in range(min_port,max_port): try: response=scan_host(host,port) if response ==0: print("Port %d: Open" %(port)) except Exception,e: pass stop_time=datetime.now() total_time_duration=stop_time -start_time print("\n Scanning Finished At %s ..." % (time.strftime("%H:%M:%S"))) print("Scanning Duration:%s..." %(total_time_duration)) print("Have a nice day ...Sergeant Exploiter (Sploit)") JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Before using the following port scanner, you may want to check a few things first: Is the firewall on your computer blocking the port scanner? Is the device your computer connected to blocking certain ports? Is the computer you are trying to scan blocking ports with its firewall? Do you know the correct name of the host that you are trying to scan? Can you create a server on one computer and connect to it with a client on the other? If none of the above points are cause for your problem, the program shown below may work for you: #! /usr/bin/env python3 import argparse import collections import itertools import multiprocessing import operator import socket PURPOSE = 'Scan for open ports on a computer.' PORTS = range(1 << 16) POOL_SIZE = 1 << 8 TIMEOUT = 0.01 def main(): """Get computer to scan, connect with process pool, and show open ports.""" parser = argparse.ArgumentParser(description=PURPOSE) parser.add_argument('host', type=str, help='computer you want to scan') host = parser.parse_args().host with multiprocessing.Pool(POOL_SIZE, socket.setdefaulttimeout, [TIMEOUT]) \ as pool: results = pool.imap_unordered(test, ((host, port) for port in PORTS)) servers = filter(operator.itemgetter(0), results) numbers = map(operator.itemgetter(1), servers) ordered = sorted(numbers) print(f'Ports open on {host}:', *format_ports(ordered), sep='\n ') field_names = 'family', 'socket_type', 'protocol', 'canon_name', 'address' AddressInfo = collections.namedtuple('AddressInfo', field_names) del field_names def test(address): """Try connecting to the server and return whether or not it succeeded.""" host, port = address for info in itertools.starmap(AddressInfo, socket.getaddrinfo(host, port)): try: probe = socket.socket(info.family, info.socket_type, info.protocol) except OSError: pass else: try: probe.connect(info.address) except OSError: pass else: probe.shutdown(socket.SHUT_RDWR) return True, port finally: probe.close() return False, port def format_ports(ports): """Convert port numbers into strings and show all associated services.""" if ports: for port in ports: try: service = socket.getservbyport(port) except OSError: service = '?' yield f'{port:<5} = {service}' else: yield 'None' if __name__ == '__main__': main()

Related questions

0 votes
    I am trying to implement the Hateoas using spring boot. In my UserController class i have used the below ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    Heyy mates..Am an icse student can anyone tell me any importance for java please its urgent I have my exam ... please for icse java. Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    Give me some Information about Quantum Computer… Please…don’t copy from Google or any other sites… Don’t give me any irrelevant answer… Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I am trying to make an app that can get the patient's symptoms as inputs and outputs the three most likely ... classes[sortedshit[2]]) Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    If I use a while loop for my below code, it is not giving the desired output, but when i use for loop i am anle ... x += 1 print(Comm) Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    I'm trying to open up a PDF as an image using Wand. If I run the code below in Jupyter Notebook ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Hey there Stack Overflow. I'm trying to build a testing script that should mix outputting changing ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I want to change a couple of files at one time, iff I can write to all of them. I'm wondering if I ... to this problem look like? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    What is the best way to open a file as reading/write if it exists, or if it does not, then create it and ... to do the opening part. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    How to check which Python version is interpreting my script? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I am receiving the error: ValueError: Wrong number of items passed 3, placement implies 1, and I am struggling to ... 'sigma'] = sigma Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    When I run pip3 install -r requirements.txt on the project I get this error message: pip._vendor.pkg_resources. ... on my machine. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I am a number I am not an odd number I am higher than 90 I am not higher than 100 If you subtract me from 100, you get nothing. What number am I?...
asked Feb 13, 2021 in Education by JackTerrance
...