Quarismo Quarismo - 7 days ago 4
Python Question

Python TCP port scanner

I'm trying to create a TCP port scanner in Python that accepts a number of arguments (-all (displays all ports, both open and closed for the target), -open (only displays the open ports on the target), -target (specify target IP, subnet or hostname) and -range (specify port range).

Currently I've only managed to code the options used in the program, my code is as follows:

import optparse

parser = optparse.OptionParser()
parser.add_option('-all', dest='allPorts', help='displays all ports regardless of status')
parser.add_option('-open', dest='openPorts', help='displays only open ports')
parser.add_option('-target', type='string', dest='targetIP', help='specify target IP address, subnet or hostname')
parser.add_option('-range', type='string', dest='portRange', help='specify port range')

(options, args) = parser.parse_args()

I'm unsure how to continue with the program, particularly with the -all / -open options, any help would be greatly appreciated.


I have modified one answer posted here, Actually i wanted to edit that answer but deleted by the author.
Try Following:

res = ""
for x in data[:3]:
    res += x
    res.replace("o", "0")
print res


res = ""
for x in data[:3]:
    res = res + x
print res.replace("o", "0")

Try Last one.