Discovery troubleshooting: Port Scan Natively Using Bash on LinuxIssue <!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } When troubleshooting Discovery issues, carrying out a port scan of a device to see whether the ports are open and responding is often necessary. This scan is normally done from the MID server host server to the device that is not being discovered. Release<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Any Resolution<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Applications such as nmap and zenmap can be used to obtain this information, but it can also be done by using a small Bash script on Linux, which avoids having to install third-party software. Script Process Log in to the Linux MID server host server.Using the editor of your choice (for example, vim, gedit, or emacs), enter the following script. Note: For this script to run properly, the timeout command, which allows commands to time out after a set period of time, must be installed. #!/bin/bash# Script: discoports.sh# Use: Checks for the ports required by Discovery, on a remote host.# remhost="" # Script requires the "timeout" command - if it's not available, exit....command -v timeout >/dev/null 2>&1 || { echo >&2 "timeout command is not available! Aborting."; exit 1; } # Check for an argument being passed (should be the hostname/IP Address) if none passed, prompt for it!if [ -z "$1" ]then while [ "$remhost" = "" ] do echo -n "Enter the hostname or IP Address of the remote host: " read remhost doneelse remhost=$1fi # Define the array that contains the port numbers we wish to check.declare -a DPort=(22 53 80 135 137 161 427 443 515 548 5060 5480 5989 9100) # Run through the array, and display if the port is open or closed.for i in "${DPort[@]}"do timeout 1 bash -c "cat < /dev/null > /dev/tcp/$remhost/$i" if [ $? -eq 0 ]; then printf "%-5s %-4s %-10s\n" "Port:" "$i" "--> Open" else printf "%-5s %-4s %-10s\n" "Port:" "$i" "--> Closed" fi done Save the script as discoports.sh and make it executable (chmod ug+x discoports.sh). Example Use Log in to the Linux MID server host server.Run the script. You can either pass the TCP IP address/Hostname as an argument to the script or you will be prompted for it. The script as written will check all of the ports that are commonly used by Discovery. $ ./discoports.sh hostname.com This command would take the argument "hostname": hostname.com and attempt to check for open ports on that host. $ ./discoports.sh 10.1.10.10 This command would take the argument IP Address: 10.1.10.10 and attempt to check for open ports on that host. $ ./discoports.sh Enter the hostname or IP Address of the remote host: As no argument has been passed to the script, it will prompt for the hostname or IP Address of the remote host. The output from the script, will resemble the following example: ./discoports.sh myhost.com Port: 22 --> Closed Port: 53 --> Closed Port: 80 --> Open Port: 135 --> Closed Port: 137 --> Closed Port: 161 --> Closed Port: 427 --> Closed Port: 443 --> Open Port: 515 --> Closed Port: 548 --> Closed Port: 5060 --> Closed Port: 5480 --> Closed Port: 5989 --> Closed Port: 9100 --> Closed