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.

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top