Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
Threaded Python multiple ports scanner
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
Just check lot of ports for server.
Free to use.
Reviews (1)
byjdcontrib, November 4, 2016
1 of 1 people found this review helpful
Better timeout control (default was 127 sec), and added performance data output for future analysis.
#!/usr/bin/python
"""
Threaded Python multiple port scanner
"""
import threading
import socket
import time
import getopt
import sys
def usage():
print "Usage: %s -H [-w ] [-c ] -p \"\"" % (sys.argv[0])
try:
optlist, args = getopt.getopt(sys.argv[1:], 'H:w:c:p:h')
except getopt.GetoptError:
usage()
sys.exit(2)
server = None
warning = 5 # defaul value
critical = 10 # default value
ports = None
perfmon = " | "
msg = ""
exit_code = 0;
for opt, arg in optlist:
if opt == '-h':
usage()
sys.exit(2)
if opt == '-H':
server = arg
if opt == '-p':
ports = arg
if opt == '-w':
warning = int(arg)
if opt == '-c':
critical = int(arg)
timeout = critical
if ports == None or server == None:
print "Server or ports not entered."
usage()
sys.exit(2)
def check_port(server,port):
global perfmon
global msg
global exit_code
s = socket.socket()
s.settimeout(timeout)
start_time = time.time()
if s.connect_ex((server,port)) == 0:
time_value = time.time() - start_time
perfmon += "port%s=%.6fs;;;0.000000;0.000000 " % (port,time_value)
ports_opened.append(port)
# check opening time and decide - warning or critical
if time_value > critical:
msg += " Time is CRITICAL %ss for port %s " % (time_value,port)
exit_code = 2
if time_value > warning and time_value
#!/usr/bin/python
"""
Threaded Python multiple port scanner
"""
import threading
import socket
import time
import getopt
import sys
def usage():
print "Usage: %s -H [-w ] [-c ] -p \"\"" % (sys.argv[0])
try:
optlist, args = getopt.getopt(sys.argv[1:], 'H:w:c:p:h')
except getopt.GetoptError:
usage()
sys.exit(2)
server = None
warning = 5 # defaul value
critical = 10 # default value
ports = None
perfmon = " | "
msg = ""
exit_code = 0;
for opt, arg in optlist:
if opt == '-h':
usage()
sys.exit(2)
if opt == '-H':
server = arg
if opt == '-p':
ports = arg
if opt == '-w':
warning = int(arg)
if opt == '-c':
critical = int(arg)
timeout = critical
if ports == None or server == None:
print "Server or ports not entered."
usage()
sys.exit(2)
def check_port(server,port):
global perfmon
global msg
global exit_code
s = socket.socket()
s.settimeout(timeout)
start_time = time.time()
if s.connect_ex((server,port)) == 0:
time_value = time.time() - start_time
perfmon += "port%s=%.6fs;;;0.000000;0.000000 " % (port,time_value)
ports_opened.append(port)
# check opening time and decide - warning or critical
if time_value > critical:
msg += " Time is CRITICAL %ss for port %s " % (time_value,port)
exit_code = 2
if time_value > warning and time_value