OBV
OBV

Reputation: 1259

Listening on multiple ports?

Can't you listen on a port range with netcat? You can scan a range, but not listen it appears. So only solution is scripting?

Upvotes: 16

Views: 29963

Answers (4)

warybyte
warybyte

Reputation: 196

I know this post is old, but I recently found a decent solution for this in the form of a nice one-liner. Shell = bash, OS = Redhat 7.

for j in 202{0..5}; do nc -lvnp $j & done

This should open up a number of listening ports from 2020 to 2025, or whatever range you want.

If you are not a root user but a sudoer and have to listen to ports below 1024 add sudo before nc command.

for j in 101{0..5}; do sudo nc -lvnp $j & done

Edited : n/c: The local port parameter was missing. {-p}

Upvotes: 11

FilBot3
FilBot3

Reputation: 3708

If you are looking to scan your destination through multiple local ports, you can use the -p <PORT> option[1]. That tells netcat to look through that local port, much similar to when telling it to setup a backdoor listener on said port. You can also string a bunch of those ports together if they are split up. Here is an example I just used.

$ nc -vvz -p 80 -p 8080 -p 443 testserver.mycompany.com 3066

That did my trick. Of course you can also list multiple destination ports to make it scan those also through each of your local ports.

[1] http://www.instructables.com/id/More-Fun-with-netcat/step2/Basic-Netcat-commands/

Upvotes: 2

Armin
Armin

Reputation: 113

or iptables,

iptables -t nat -A INPUT -p tcp --dport 8080 -j REDIRECT --to-port 80

Upvotes: 0

paddy
paddy

Reputation: 63471

I don't think it supports that functionality. If you are happy with any old solution, you could use the ncat edtition of netcat, and set up forwarding for each port. You can spawn a forwarder for all but the first port, then listen on the first port:

first_port=2999
last_port=3004

for (( i = first_port+1; i <= last_port; i++ )) do
    ncat -l -k -p $i -c "nc localhost $last_port" &
done

ncat -l -k -p $first_port

I admit, it's grungey.

Upvotes: 3

Related Questions