Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 on listening state..

share|improve this question
    
occupy you mean about let an specific TCP port oppened on listen state? –  Diogo Mar 7 '12 at 12:42
1  
This question makes no sense. A port is "closed" by default when nothing is listening on it. –  Ingmar Hupp Mar 7 '12 at 12:43
    
This is what I want - some utility that will be listening on the port of my choosing and do nothing. –  Vic Mar 7 '12 at 12:49
add comment

7 Answers

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

share|improve this answer
    
It works on Windows??? I tried this command here and it was not recognized. –  Diogo Mar 7 '12 at 13:05
3  
I was going to post this as my answer! =p You can download netcat here: joncraton.org/files/nc111nt.zip It's a pretty old tool, but I think people failed to realize just how useful it can be. –  ekaj Mar 7 '12 at 13:05
    
@Diogo Rocha You know it is a downloaded program, correct? –  ekaj Mar 7 '12 at 13:06
2  
I didn't know... It would be nice if the answear post the link to download then... –  Diogo Mar 7 '12 at 13:07
    
Reading comments generally helps as well –  ekaj Mar 7 '12 at 13:08
show 5 more comments

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.

share|improve this answer
1  
humor me - since when when does Wireshark actually behave like a service listening on a port? It passively records the traffic. –  Florenz Kley Mar 7 '12 at 13:20
    
@FlorenzKley you're right, it doesn't... I interpreted his question as how to view the network traffic on a certain port though, since wouldn't it be trivial for the O.P. to just run two copies of his program at once on the same port (to see what happens if another program is already listening on the port)? –  Breakthrough Mar 7 '12 at 13:24
add comment

The netpipes tools faucet and hose have always served me well, simplifying stdin and stdout for my programs to use over the network.

Similar to netcat.

Ubuntu description:

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 - .
share|improve this answer
    
Thanks, but I need it for Windows... –  Vic Mar 7 '12 at 13:49
    
Not even Cygwin? –  Marcos Mar 7 '12 at 21:19
add comment

You have

TCP Listen: http://www.allscoop.com/tcp-listen.php

Port Peeker: http://www.linklogger.com/portpeeker.htm

Microsoft's Command-line utility Portqry.exe

share|improve this answer
add comment

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 iperf.exe or 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.

share|improve this answer
add comment

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.

share|improve this answer
add comment
up vote 0 down vote accepted

I ended up writing an application in Java for this... Thanks everyone.

share|improve this answer
5  
Maybe you can share it for others who are searching for a similar solution? –  slhck Mar 9 '12 at 18:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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