Netcat command: Unknown IP address - windows

I have two laptops that each has connected to the Internet by landline (two different lines/modem). One is Mac and the other is Windows. I want to send a message from Windows to the Mac.
I installed NetCat on Mac using, brew install netcat, based on this page.
I installed NetCat on Windows based on this page.
I ran following command in Mac terminal in order to see what is my IP address: $ ipconfig getifaddr en0 it printed: 169.254.136.39
In Mac terminal: $ nc -u -l -p 4444. Seems it is ready for incomming messages.
In Windows terminal: $ nc -u 169.254.136.39 4444. I get a new line and I assume connection has established. However, when I enter a message and hit Enter, nothing happens :(
When I replace above command with nc -u -v -n 169.254.136.39 4444 in Windows and nc -u -l -n -p 4444 in Mac, then I get: (UNKNOWN) [169.254.136.39] 4444 (?) open
I have no idea what is wrong? I confirm Firewal is off on my Mac.

Related

SSH tunnelling in Catalina to use Screen Sharing (VNC)

I am using the following to try and ssh tunnel to a remote machine via a master one:
ssh -J username1#1.2.3.4 username2#5.6.7.8 -L 5900:localhost:5900
Password:
Password:
bind [::1]:5900: Address already in use
channel_setup_fwd_listener_tcpip: cannot listen to port: 5900
Could not request local forwarding.
This works perfectly on Mojave (executing vnc://localhost afterwards in a new Terminal window). But in Catalina, no. I get: You cannot control your own screen.
About port 5900 already in use, I ran sudo lsof -i tcp:5900 and I can't see any process using that port.
I finally made tunnelling work in Catalina:
First ssh -J username1#1.2.3.4 username2#5.6.7.8 -L 5901:localhost:5900.
Then open 'vnc://localhost:5901' in a new Terminal window.

Cross-platform check for port in use

I'm looking for a cross-platform way to check if a port is in use so I can print a warning message.
I have accomplished this in macOS:
if lsof -Pi :8080 -sTCP:LISTEN -t >/dev/null; then
echo "Port 8080 is already in use"
fi
But this bash script needs to also work on Windows machines. I was looking at something like netstat -aon | find "8080", but I'm unsure how to use that in my script (don't have a Windows machine).
Is there an efficient way to do this? If it helps, the Windows machines have WSL available to them (but lsof doesn't appear to work yet).
While I'm certain the other answers would work in certain situations, I just wanted to note I ended up going with the following solution for my own work:
if echo PING | nc localhost 8080 >/dev/null; then
echo "Port 8080 in use"
fi
Im not sure how your network looks like but maybe nmap will be a solution for you. You can scan ports for every pc in your local network using only linux.
If port is open, that mean is in use. This solution will work for any system.
apt-get install nmap
for example like this:
if nmap -p 8080 <ip address> | grep -wq "open"
then
echo "Port 8080 is already in use"
fi
Use netstat (works on windows, mac, wsl2)
Example netstat -a | grep :8080 where 8080 is the port you are interested in.
If you are on wsl1 you will need to use the windows netstat as the one included in wsl is broken. Simply set an alias to the windows netstat before using it alias netstat='/mnt/c/Windows/System32/netstat.exe'

Powershell to connect to a remote linux ssh server and executing a command line

I have to connect from a Windows 10 / Windows Server 2016 machine to a Linux machine (CentOS) to execute a command to disable a server in haproxy. On a local Linux machine the command is sudo echo "disable server http/test1" | socat tcp:127.0.0.1:9191 stdio and it works. But I have to create a script / command line to let a Windows machine do the magic. I´ve tried powercat but it will not work. So I decide to use ssh client on the Windows machine. The command line is
ssh -l haproxy-user -i private.ppk 10.0.0.20 "sudo echo "disable server http/test1" | socat tcp:127.0.0.1:9191 stdio" but I didn´t get the option to enter the passphrase for my identy file. Or is there another option to execute the command line?

Issue with netcat command in windows

I have installed netcat for windows 8.
At the command prompt I am giving the command nc -lvp 50050.
I am getting a message "listening on [any] 50050 ..."
But I am not able to type in any message. Can any one please help me what could be wrong.
I am actually trying to test spark streaming to test the messages that I am typing in host 50050
Using the command "nc -vvv -l -p 50050" I am able to start the port 50050. From which I could type in something and listen from SparkStreaming.

Why does OS X allow listening on the same TCP port twice?

I was trying to debug port allocation problems in Jenkins on OS X by listening to certain ports with netcat, which led to some weird results.
In a terminal on OS X 10.8.2:
$ uname -rs
Darwin 12.2.1
$ nc -l 54321
Then in an second terminal:
$ nc -l 54321
And in a third terminal, lsof shows that both instances have bound to the same port:
$ lsof -i | grep 54321
nc 70706 chris 3u IPv4 0x55618c024692f4d1 0t0 TCP *:54321 (LISTEN)
nc 70769 chris 3u IPv4 0x55618c0232cb8661 0t0 TCP *:54321 (LISTEN)
On Linux:
First terminal:
$ uname -rs
Linux 3.2.0-34-generic
$ nc -l 54321
Second terminal:
$ nc -l 54321
nc: Address already in use
Why doesn't OS X also report that the address is already in use?
The binary on OS X is setting the SO_REUSEPORT socket option, which allows completely duplicate bindings (setsockopt on OS X). You can verify this using dtrace on OS X.
The netcat binary on Linux does not do this, so you get a bind error as expected. Again, you can verify that using strace. I belive SO_REUSEPORT is deprecated, or not even available on newer Linux kernels.

Resources