13

Is it possible to send text messages between two users of the same LAN, but the first running Windows with cmd and the second running Linux/Unix?

I am not looking for an instant messaging service. I would like to type in the Linux shell something like

write [email protected]:port message

so that the Windows user can read in its cmd window the text message; then the Windows user should be able to reply with another command. Is it possible?

I have read about the Windows msg command but it doesn't work in all the versions of the OS. Is there anything else?

Instead of PuTTY, I would like to use the Linux shell and the Windows cmd.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
BowPark
  • 4,811
  • 12
  • 47
  • 74

4 Answers4

6

On Unix: nc -l 192.168.1.10 32849

On Windows: telnet 192.168.1.10 32849

Where 32849 is an arbitrary port allowed in firewall rules, and the IP is the listening IP of the Unix machine. nc is the netcat utility.

  • Great idea! on **windows7 x64** I needed to install the telnet client "windows feature". the idea was to do `pkgmgr /iu:"TelnetClient"` but that resulted in `Operation failed with 0x8007000B An attempt was made to load a program with an incorrect format.`, after logging I saw `You cannot service a running 64-bit operating system with a 32-bit version`. Got it working with `c:\windows\sysnative\dism.exe /online /norestart /logpath:"c:\foo.txt" /enable-feature /ignorecheck /featurename:"TelnetClient"` emphasis on `sysnative`. It installed `c:\windows\sysnative\telnet.exe`. – n611x007 Sep 24 '15 at 15:19
  • I had to use `-p` as in `nc -l 192.168.1.10 -p 32849`, thanks to [JohnMurhy](http://stackoverflow.com/a/29894103/611007)! – n611x007 Sep 24 '15 at 15:32
  • I had to use different IP in the two commands. (the other machine's IP on each side.) – n611x007 Sep 24 '15 at 15:34
  • I tested again after these new comments, I do not need the -p flag using the [Free]BSD nc command. I get "wolf% sudo nc -l 10.0.0.1 -p 8888 _nc: cannot use -p and -l_". I also neglected to mention you do need superuser access to bind to arbitrary ports. I do not know why naxa needs different IPs or even how it's possible that that is working, it should not work. This is because the -l flag means it is listening locally on the *nix IP and port combination. It has nothing to do with the Windows machine's IP. Telnet is acting as the client in this scenario. – p̻̻̥r̥̻̥o̻j̤͛ec͔t̞dp Sep 24 '15 at 22:27
3

The idea from projectdp's answer: netcat on linux serves a telnet on win. Needed to -p and different IP addresses on the two machine however:

  • In Linux: netcat -l 10.0.0.2 -p 14415 - if your windows is on 10.0.0.2

  • In Windows: telnet 10.0.0.1 14415 - if your linux is on 10.0.0.1

  • To quit telnet press ^] which means Ctrl+] and then typing q.

  • To choose your arbitrary port like 14415 a handy table is at David Vereb.

However on win7 x64 I had to enable telnet first, long story short:

  • c:\windows\sysnative\dism.exe /online /norestart /logpath:"c:\foo.txt" /enable-feature /ignorecheck /featurename:"TelnetClient"

  • The problem in the original attempt was that pkgmgr tried to use 32-bit dism and whined for 64-bit. I've got the sysnative idea from Osman Shener.

  • It installs to c:\windows\sysnative\telnet.exe. I put c:\windows\sysnative in the PATH environment variable with sysdm.cpl.

  • If you have DeVuan or Ubuntu for Linux, sudo apt-get install netcat-traditional

The chat looked like:

devuan-netcat win7-telnet

n611x007
  • 957
  • 3
  • 11
  • 21
  • Hello naxa, I'm a little confused by your test here, how can you possibly open a listening socket on linux using the windows host's IP? You are not listening _for_ the windows hosts IP, you are listening _on_ the linux hosts IP and port. When you are using telnet from the windows host you are acting as a client joining the linux machine's listening socket and IP. I'll have to test it with your method. – p̻̻̥r̥̻̥o̻j̤͛ec͔t̞dp Sep 24 '15 at 21:24
  • Naxa, I tried and I do not know how you are successfully connecting these two machines. nc should be listening on the local ip address and local port. telnet should be connecting to the remote ip and remote port... can you list the output of your ipconfig/ifconfig on each machine? – p̻̻̥r̥̻̥o̻j̤͛ec͔t̞dp Sep 24 '15 at 22:30
  • @projectdp ah I found this again. So in the end I agree with you it shouldn't even have worked but apparently it did and it only did like this. I think I didn't answer because I wanted to test through this. Unfortunately I got carried away and I do not have the machines any more. I think they were virtualized which I know to be able to cause the weirdest networking anomalies in general... – n611x007 Feb 21 '17 at 02:38
1

How about NET SEND {name1 | * | /DOMAIN[:name] | /USERS} message on the windows machine, and echo "message" | smbclient -M name2 on the linux box? name1 and name2 are the netbios names of the machines.

noleti
  • 111
  • 2
  • please clarify a little bit ! 'NET SEND' command is generally used for win to win message passing using 'messenger'. Is it possible to use in case of Bash to win also ?? – diffracteD Jun 17 '16 at 10:38
  • @diffracteD I don't have a windows machine to test. I assume with "Bash to win", you mean from linux to windows? My second example should do exactly that – noleti Jun 20 '16 at 12:45
1

There is an interesting tool which allows you to execute windows commands from Linux, the name is winexe.

So you can send a message from the same machine to the console just typing: winexe -U domain/user%password --interactive=1 //WindowsMachine "msg console \"Your message goes here.\""

As you can see noleti's answer is much simpler but with winexe you can also open a calc or whatever you want in that machine. We have been using it to do unattenden installs in Windows machines from a batch script in Linux. Pretty cool and time saving...

YoMismo
  • 4,005
  • 1
  • 15
  • 31