Is there some basic utility to open a specific network TCP port on my machine?
I need to test how my program deals with ports in the listening state.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
netcat should do what you want. Have it listen on you machine and echo stuff to STDOUT:
nc -4 -k -l -v localhost 1026
when you want it to close when the connection ends, don't use -k
Try iperf. There is a version for Windows. You can just run it like
iperf -s -p 1234, and it will listen on port 1234. You can then connect to that port from a remote machine by doing something like:
telnet 192.168.1.1 1234 iperf -c 192.168.1.1 1234 portqry -n 192.168.1.1 -e 1234
You would need to obtain
portqry.exe for the last two. iPerf isn't strictly designed for this task, but it's great for troubleshooting connectivity, bandwidth availability, stress testing links, etc.
It looks like this utility will do exactly what you want, even displaying the received data if you like: http://www.drk.com.ar/builder.php
It has a GUI rather than just a command line, an advantage for some.
This is the perfect use for Wireshark, a packet and protocol analyzer which sits in-between the Windows/Linux networking stack.
It will allow you to view all TCP/UDP packets that are received by your entire machine, regardless of the port. You can also tell the program to filter out only packets sent across a certain port for further analysis. The advantage to Wireshark is that it provides very detailed messages for each packet - source, destination, port, MAC addresses, data, dates, checksums, etc. Very useful (and free!) tool.
The netpipes tools faucet and hose have always served me well, simplifying
stdout for my programs to use over the network.
Similar to netcat.
The netpipes package makes TCP/IP streams usable in shell scripts. It can also simplify client/server code by allowing the programmer to skip all the tedious programming bits related to sockets and concentrate on writing a filter, or other service.
EXAMPLES This creates a TCP-IP socket on the local machine bound to port 3000. example$ faucet 3000 --out --verbose tar -cf - . Every time some process (from any machine) attempts to connect to port 3000 on this machine the faucet program will fork(2) a process and the child will exec(2) a tar -cf - .
TCP Listen is the BEST answer IMHO. I looked at and liked TCP Builder, but you NEED admin rights to run that app, you do NOT need them with TCP listener, and you also need to install TCP Builder, or unzip and copy a bunch of files, whereas TCP Listener is 1 EXE, nothing more.
TCP Listener also did not need admin rights, and when I AV scanned it nothing said it was malicious. Builder had 1 AV on Virustotal say it was bad, but it turned out to be a false positive (I hope) :)
While I got Builder to run sans admin rights, it could not hook the socket while Listener could. Once I did all my testing, I could just delete the 1 file of Listener and all was like before.
Netcat would have been nice, but I did not find a version that would work with 2012 or later server. So, to fully test if the network firewall and local firewalls allow specific TCP ports to connect, TCP listener seems like the best tool for this job.
You can use netcat's Windows version:
nc -l -v localhost -p 7
TCPView from the Sysinternals toolkit provides a very nice overview.