Issue with netcat command in windows - spark-streaming

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.

Related

Netcat command: Unknown IP address

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.

Passing additional "arguments" to a telnet connection command

I have a server that takes whatever data is sent to it and sends it back. With netcat on linux I am able to exectue the nc ip port command with an additional "argument" in a single line:
python -c print("Hello!") | nc ip port
This is equivalent to first running nc ip port to connect to the server, and later typing Hello! in the opened prompt to send the data.
While I know how to pass an output from a script to another script in windows (ex. here), I am fairly unsure how to achieve a similar result using telnet, as telnet ip port opens its own prompt (which means disabling windows commands).
I would like to know if it is at all possible with telnet to achieve what piping in linux does, or if there is a similar, minimalistic software that I could use on windows.

Using expect on a Mac to access a router via telnet

I'm trying to write a script on a Mac which should access a router via telnet. This is to enhance the router's power, which cannot be done via web.
The problem is that the telnet channel is blocked, and in order to unlock it I need to run the following instruction:
/users/shared/telnetenable - 200CC8132A36 admin password >/dev/udp/192.168.0.1/23
Now, I can open a telnet connection, but in order to send commands to the router I need to do all that with expect. So, my file begins with:
#!/usr/bin/expect -f
and all instructions are preceded by spawn, e.g.
spawn telnet 192.168.0.1
while the command sent to the router is:
send "wl -a wl0 txpwr 100\n"
My problem is that I do not know how to run via spawn the instruction that unlocks telnet on the router. Can anybody help me?
You don't have to use spawn to run a non-interactive command. Tcl's exec command is enough. For example:
#!/usr/bin/expect
# the ``/dev/udp/host/port'' syntax is bash specific
exec bash -c "/users/shared/telnetenable - 200CC8132A36 \
admin password > /dev/udp/192.168.0.1/23"
spawn telnet 192.168.0.1
... ...
Expect also has a system command so you can also
system "/users/shared/telnetenable - 200CC8132A36 \
admin password > /dev/udp/192.168.0.1/23"

shrewsoft command line interface to connect and terminate vpn on ubuntu

Shrewsoft [1] provides a command line interface for setting up the vpn tunnel automatically without any user intervention, such as by using the following command
ikec -u username -p password -r configuration -a
IS there any way to detect if the connect attempt was successful such as by reading live logs and how can we terminate the vpn tunnel after some time using the command line. Any help will be appreciable.
By looking at the terminal output from ikec -u username -p password -r configuration -a, you can tell if the connection was successful; if the output has a line ii : tunnel enabled, that means the connection was successful and should work. If you get a message such as >> : detached from key daemon or failed to connect to key daemon, it means there was a problem with the connection (https://askubuntu.com/a/793336/705434 suggests running sudo /usr/sbin/iked for a solution to this particular error). To exit the ikec command, just type q into the terminal.
EDIT: it looks like this page (https://gist.github.com/fschabmeyer/22b759994cf852df7e9b) has a shell script that can handle the detection, you should be able to add a case to exit the command automatically after a certain amount of time.

How to stop socat from quitting?

I am using socat for windows as a client to tunnel DNS over SSH, it works perfectly until the ssh connection dies or becomes temporarily unavailable - when this happens the socat windows client terminates and requires restarting.
I am using the following command on windows client:
socat -s udp-recvfrom:53,reuseaddr,bind=127.0.0.1,fork tcp:127.0.0.1:5377
Does anyone know a way to prevent the socat client from quitting when the ssh connection becomes unavailable? The help file suggests the -s switch solves this but it doesn't.
Following your comment, a loop in VBScript (what Windows Scripting Host uses) is easier:
Do
WshShell.Run "socat.exe -s udp-recvfrom:53,reuseaddr,bind=127.0.0.1,fork tcp:127.0.0.1:5377",0,True
Loop While True

Resources