Listening on multiple ports?
Asked Answered
B

4

15

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?

Burushaski answered 20/9, 2013 at 1:56 Comment(1)
T
11

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}

Theotokos answered 20/4, 2018 at 20:37 Comment(2)
Does there need to be a semicolon before the done statement?Iapetus
@Iapetus - don't think so he's backgrounding all those invokes of nc -lvnp $j.Ornas
S
3

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.

Selenium answered 20/9, 2013 at 2:21 Comment(2)
Good pick for ncat vs netcat. ncat is supposed to be more secure than netcat, and is actively maintained by nmap.Irresolution
And for checking is ports open nc can accepts range as ports. $ nc -zv 192.168.56.10 2999-3004Unsay
I
2

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/

Irresolution answered 3/2, 2014 at 16:24 Comment(0)
L
0

or iptables,

iptables -t nat -A INPUT -p tcp --dport 8080 -j REDIRECT --to-port 80
Lepley answered 24/9, 2013 at 13:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.