mirror of
https://github.com/ChronosX88/PyNesca.git
synced 2024-11-21 20:52:18 +00:00
Merge pull request #5 from S0Ulle33/dev
Small changes associated with PEP8.
This commit is contained in:
commit
cf5ee185cf
@ -34,13 +34,13 @@ class MainPresenter:
|
|||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
def on_thread_exit(self, is_last):
|
def on_thread_exit(self, is_last):
|
||||||
if is_last == True:
|
if is_last:
|
||||||
self.isScanEnabled = False
|
self.isScanEnabled = False
|
||||||
self.ui.startButton.setText("Start")
|
self.ui.startButton.setText("Start")
|
||||||
return
|
return
|
||||||
count = 0
|
count = 0
|
||||||
for thr in self.threads:
|
for thr in self.threads:
|
||||||
if thr.is_running == True:
|
if thr.is_running:
|
||||||
count = count + 1
|
count = count + 1
|
||||||
self.setCurrentThreadsLabel(count)
|
self.setCurrentThreadsLabel(count)
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ class MainPresenter:
|
|||||||
count = 0
|
count = 0
|
||||||
is_last_thread = False
|
is_last_thread = False
|
||||||
for i in self.threads:
|
for i in self.threads:
|
||||||
if i.is_running != True:
|
if not i.is_running:
|
||||||
count += 1
|
count += 1
|
||||||
if count == len(self.threads):
|
if count == len(self.threads):
|
||||||
is_last_thread = True
|
is_last_thread = True
|
||||||
@ -90,7 +90,7 @@ class ScanThread(QThread):
|
|||||||
count = 0
|
count = 0
|
||||||
is_last_thread = False
|
is_last_thread = False
|
||||||
for i in self.presenter.threads:
|
for i in self.presenter.threads:
|
||||||
if i.isRunning() != True:
|
if not i.isRunning():
|
||||||
count += 1
|
count += 1
|
||||||
if count == len(self.presenter.threads):
|
if count == len(self.presenter.threads):
|
||||||
is_last_thread = True
|
is_last_thread = True
|
||||||
|
72
Parser.py
72
Parser.py
@ -2,53 +2,75 @@ import ipaddress
|
|||||||
|
|
||||||
|
|
||||||
def getPortsFromString(ports):
|
def getPortsFromString(ports):
|
||||||
# Converts ports from form 20-40,100-900,40000-70000
|
"""
|
||||||
# It will automatically prune off non-existent ports (<1 >65535)
|
Parses ports from string, returns them as integers in the list.
|
||||||
if ports is None:
|
Handles non-existent ports and non-port values.
|
||||||
return [21, 22, 23, 25, 80, 443, 110, 111, 135, 139, 445, 8080, 8443, 53, 143, 989, 990, 3306, 1080, 5554, 6667, 2222, 4444, 666, 6666, 1337, 2020, 31337] # Change to default ports from constant
|
"""
|
||||||
else:
|
if ports:
|
||||||
if "-" not in ports:
|
# Using set to avoid repetitions
|
||||||
tports = ports.split(",")
|
parsed = set()
|
||||||
print(tports)
|
ports = ports.split(",")
|
||||||
else:
|
for port in ports:
|
||||||
ports = ports.split(",")
|
try:
|
||||||
tports = []
|
# Input is in range form ("100-200"):
|
||||||
for port in ports:
|
if '-' in port:
|
||||||
if "-" not in port:
|
start, end = map(int, port.split('-'))
|
||||||
tports.append(int(port))
|
parsed.update(
|
||||||
|
[p for p in range(start, end + 1) if 65355 >= p > 0])
|
||||||
|
# Input is a single port ("80"):
|
||||||
else:
|
else:
|
||||||
# I made this one line because I wanted to
|
parsed.add(int(port))
|
||||||
tports.extend(
|
except ValueError as e:
|
||||||
list(range(int(port.split("-")[0]), int(port.split("-")[1]) + 1)))
|
# If we get any not integer just ignore it
|
||||||
ports = [int(n) for n in tports if int(n) > 0 and int(n) < 65536]
|
pass
|
||||||
return ports
|
return sorted(list(parsed))
|
||||||
|
else:
|
||||||
|
# Change to default ports from constant
|
||||||
|
return [21, 22, 23, 25, 80, 443, 110, 111, 135, 139, 445, 8080, 8443, 53, 143, 989, 990, 3306, 1080, 5554, 6667, 2222, 4444, 666, 6666, 1337, 2020, 31337]
|
||||||
|
|
||||||
|
|
||||||
def getCIDRFromRanges(ips):
|
def getCIDRFromRanges(ips):
|
||||||
|
"""
|
||||||
|
Parses ip input string, returns the generator over them.
|
||||||
|
|
||||||
|
Supports next inputs:
|
||||||
|
1) 1.2.3.4
|
||||||
|
2) 192.168.0.0/24
|
||||||
|
3) 1.2.3.4 - 5.6.7.8
|
||||||
|
Any non-ip value will be ignored.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# A set to contain non repeating ip objects from ipaddress
|
||||||
ip_objects = set()
|
ip_objects = set()
|
||||||
inputs = [ip.strip() for ip in ips.split(',')]
|
inputs = [ip.strip() for ip in ips.split(',')]
|
||||||
|
|
||||||
for input_ in inputs:
|
for input_ in inputs:
|
||||||
try:
|
try:
|
||||||
|
# Input is in range form ("1.2.3.4 - 5.6.7.8"):
|
||||||
if '-' in input_:
|
if '-' in input_:
|
||||||
input_ips = input_.split('-')
|
input_ips = input_.split('-')
|
||||||
ranges = {ipaddr for ipaddr in ipaddress.summarize_address_range(
|
ranges = {ipaddr for ipaddr in ipaddress.summarize_address_range(
|
||||||
ipaddress.IPv4Address(input_ips[0]),
|
ipaddress.IPv4Address(input_ips[0]),
|
||||||
ipaddress.IPv4Address(input_ips[1]))
|
ipaddress.IPv4Address(input_ips[1]))
|
||||||
}
|
}
|
||||||
ip_objects.update(ranges)
|
ip_objects.update(ranges)
|
||||||
|
# Input is in CIDR form ("192.168.0.0/24"):
|
||||||
elif '/' in input_:
|
elif '/' in input_:
|
||||||
network = ipaddress.ip_network(input_)
|
network = ipaddress.ip_network(input_)
|
||||||
ip_objects.add(network)
|
ip_objects.add(network)
|
||||||
|
# Input is a single ip ("1.1.1.1"):
|
||||||
else:
|
else:
|
||||||
ip = ipaddress.ip_address(input_)
|
ip = ipaddress.ip_address(input_)
|
||||||
ip_objects.add(ip)
|
ip_objects.add(ip)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print(e)
|
# If we get any non-ip value just ignore it
|
||||||
|
pass
|
||||||
|
|
||||||
for ip_obj in ip_objects:
|
for ip_obj in ip_objects:
|
||||||
if not isinstance(ip_obj, ipaddress.IPv4Address):
|
# The object is just one ip, simply yield it:
|
||||||
for ip in ip_obj.hosts():
|
if isinstance(ip_obj, ipaddress.IPv4Address):
|
||||||
yield ip
|
|
||||||
else:
|
|
||||||
yield ip_obj
|
yield ip_obj
|
||||||
|
# The object is a network, yield every host in it:
|
||||||
|
else:
|
||||||
|
for host in ip_obj.hosts():
|
||||||
|
yield host
|
||||||
|
14
main.py
14
main.py
@ -19,15 +19,17 @@ class MyWin(QtWidgets.QMainWindow):
|
|||||||
self.isScanActive = False
|
self.isScanActive = False
|
||||||
|
|
||||||
def startButtonClicked(self):
|
def startButtonClicked(self):
|
||||||
if self.presenter.isScanEnabled == False:
|
if self.presenter.isScanEnabled:
|
||||||
self.presenter.isScanEnabled = True
|
|
||||||
self.ui.startButton.setText("Stop")
|
|
||||||
self.presenter.startScan(self.ui.ipLine.text(), self.ui.portsLine.text(), self.ui.threadsLine.text(),
|
|
||||||
self.ui.timeoutLine.text())
|
|
||||||
else:
|
|
||||||
self.presenter.isScanEnabled = False
|
self.presenter.isScanEnabled = False
|
||||||
self.ui.startButton.setText("Start")
|
self.ui.startButton.setText("Start")
|
||||||
self.presenter.stopScan()
|
self.presenter.stopScan()
|
||||||
|
else:
|
||||||
|
self.presenter.isScanEnabled = True
|
||||||
|
self.ui.startButton.setText("Stop")
|
||||||
|
self.presenter.startScan(self.ui.ipLine.text(),
|
||||||
|
self.ui.portsLine.text(),
|
||||||
|
self.ui.threadsLine.text(),
|
||||||
|
self.ui.timeoutLine.text())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user