Question

To test my implementation of a NAT, I want to send TCP packets from one internal host to two different external hosts, and make sure that the source port for both streams of packets that leave the NAT have the same source port. How can I control the source port? wget uses different source ports for separate TCP connections.

Was it helpful?

Solution

Maybe you want to try netcat with -p option, if you don't want to write code by yourself, example: $ nc -p 31337 www.google.com 80

Here is the explanation for "-p" option from man page: Specifies the source port nc should use, subject to privilege restrictions and availability. It is an error to use this option in conjunction with the -l option.

Note though to use any port under 1024 requires root permission.

OTHER TIPS

Bind the socket to a specific local port before you connect it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top