Build precise queries to find exactly what you need
Press ESC to close
Your review has been submitted and is pending approval.
Simple shell script that uses nmap utility to check if a remote host is listening on a UDP port and what that service is
Current Version
1.1
Last Release Date
2014-06-09
Owner
Aaron Eidt
License
GPL
Compatible With
Simple shell script that uses nmap utility to check if a remote host is listening on a UDP port and what that service is.
Usage: check_udp_port: -H remote_host -p port -s service_name
-H Name or IP of remote host -p UDP port number to check -s Name of the service that should be listening on the port
Critical: if service is 'unknown' or state is not open
Warning: if service name expected does not match service name listening on the port
OK: if the port is open and service name expected matches service name listening.
NOTE for NagiosXI command definition:
nmap requires root perms to scan the port. Add the following to /etc/sudoers: NAGIOSXI ALL = NOPASSWD:/usr/local/nagios/libexec/check_udp_port *
And the command definition should be: sudo $USER1$/check_udp_port -H $HOSTNAME$ -p $ARG1$ -s $ARG2$
UPDATES: ----------------------------- v1.1: made change to egrep statement to include 0-9_- in service names
#result=`sudo /usr/bin/nmap -sU -p $port -P0 $host` result=`sudo /usr/bin/nmap -sU -p $port -P0 $host| grep ^${port}/.*` f_result=`echo $result Nmap done` p_result=`echo $f_result | awk '{print $1" "$2" "$3}'`
Good plugin, been using for a while. Today I upgraded Debian from 9.9 to 10 and this plugin stopped working. The problem is probably in grep change line 50: f_result=`echo $result | egrep -o "${port}/udp [a-zA-Z0-9_-| ]+Nmap done"` plugin output: grep: Invalid range end CRITICAL: Does anyone know how to fix this issue? I am no expert at regex Thanks
Hello, I have to give permissions to execute all the users the nmap command chmod u+s /usr/bin/nmap And I change exit value at the end, to UNKNOWN state because is confused CRITICAL state. echo "UNKNOWN: $p_result ------" exit ${STATE_UNKNOWN}
I changed the following line to avoid problems with services containing "open" in the name, e.g.: openvpn if [ `echo $f_result | egrep -c 'udp open'` -gt 0 ]; then
Thanks for this helpful tool. For some nmap-versions (e.g. nmap 5.21 on opensuse 11.4) you will have to remove an extra line with the MAC-address after the port line to get a valid result string: PORT STATE SERVICE 177/udp open xdmcp MAC Address: 00:30:48:11:22:33 (Supermicro Computer) Nmap done: 1 IP address (1 host up) scanned in 0.09 seconds As not being familiar with extended regular expressions I extended the nmap statement: result=`/usr/bin/nmap -sU -p $port -P0 $host |grep -v MAC` This works but feel free to find the respective expression for f_result.
I had to escape the dash in the egrep pattern (using GNU egrep 2.14), but after that it worked great! f_result=`echo $result | egrep -o "${port}/udp [a-zA-Z0-9_-| ]+Nmap done"`
You must be logged in to submit a review.
To:
From: