I want to know if a HP-UX machine can communicate to a remote machine (which I don't have control over) on a particular port using UDP.

I tried telnet, but it doesn't look like it supports UDP. I would use netcat, but I was unable to find any bundle. This machine is in production so I don't want to mess around compliling or installing things too much... (nmap, netcat from source...)

Any simple way to do this?

up vote 14 down vote accepted

Pinging a UDP port is kind of tricky, since there are no connections, per se. If you don't have control over the remote host, then you might never really know whether your UDP datagrams are actually being received. I assume you already know whether the remote host is reachable, via ping, traceroute, mtr, etc. (If not, check that first!)

Next, since you don't have netcat, you'll need some way of generating UDP packets.

The bash shell sends UDP packets when you redirect data to the special device /dev/udp/host/port. For example:

#!/bin/bash
host="10.10.10.10"
port=12345
echo "PING" >/dev/udp/$host/$port

Python, of course, is also fully capable of UDP, e.g.

#!/bin/python
import socket
host="10.10.10.10"
port=12345
udp_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_sock.sendto('PING', (host, port))

Regardless of how you contrive to generate your UDP "ping" packet, you'll want to know whether the target received it. If the target port is open (i.e. a service is listening at the given port), then what happens will be application-defined. Hopefully, you will notice some behaviour or indication from the remote system.

If the target port is closed (i.e. no service is listening at that port), then you should get an ICMP error packet back in response. Use your favourite wire-level network sniffer to watch for it. Or, perhaps your HP-UX system logs ICMP errors somewhere (sorry, I don't have any experience with HP-UX).

Unfortunately, if the target is firewalled, you may not get a response when the target port is closed. The only surefire way to know if the remote host is responsive is to run your UDP-data-dependent application and watch the network traffic.

You can use netcat. In OSX, this is my command:

$ nc -vnzu <IP> <PORT>
found 0 associations
found 1 connections:
1: flags=82<CONNECTED,PREFERRED>
outif (null)
src <SOURCE IP> port <SOURCE PORT>
dst <DEST IP> port <DEST PORT>
rank info not available
  • Perfect, nc works for everything! – Shoaib Khan Nov 19 at 7:05

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.