Post

[Linux] Terminal Messaging via netcat - PC & Phone Over LAN

Send messages between your phone and PC like a hacker - with netcat & bash.

[Linux] Terminal Messaging via netcat - PC & Phone Over LAN

So, with SFTP, we can easily transfer files from phone to PC-fast and smooth.

But what if I just wanna send a quick text to my PC instead? Like… can I shoot a message straight to the terminal from my phone?

And that got me thinking-

How do hackers talk to each other through terminals, like in those classic hacker movies? You know, black screens… glowing green letters… mysterious chats flying across the command line…

Well, that’s exactly what we’re gonna talk about today. (I use 🐧 Pop!OS, but this works on any Linux distro.)


🧠 Netcat-based Terminal Messaging (No Permission B.S.)

First things first-make sure you can use Termius (or any other SSH app) on your phone to connect to your PC.

Then we can start the magic work:

🟢 Step 1 (on PC)

1
nc -l -p 8888

🟢 Step 2 (on Phone)

1
nc 192.168.1.2 8888

⬆️ Change 192.168.1.2 to your PC private ip.

Once the connection is established:

  • One device listens (nc -l -p 8888)
  • The other connects (nc IP PORT)
  • Then? BOTH CAN TYPE in the same session 🫠💬

Now they’re 💞 bound 💞 in a full-duplex socket stream. You can:

  • 📝 Type from PC - appears on Phone
  • 📱 Type from Phone - appears on PC

Same session, no need for separate reverse flow.

This only works when Netcat on both ends supports full-duplex. Full-Duplex Ethernet = Two-Way Street, all modern routers support it.

Some older nc builds were single-direction only, gotta use two lanes for back-and-forth. 👇

1
2
3
4
5
6
A: nc -l -p 1234
B: nc A_IP 1234
---
B: nc -l -p 5678
A: nc B_IP 5678


Scripts

So let’s organize all these features in to sh scripts:

FeatureDescription
🌈 Colors“Phone” = Magenta, “PC” = Blue
📝 LoggingSaved to ~/Documents/Chat/chat_shared.log
♾️ Infinite loopKeeps listening / sending forever
💬 Beautiful UXHuman-readable, timestamped, stylized messages

💻 pc-chat.sh

1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash

LOG="$HOME/Documents/Chat/chat_shared.log"
mkdir -p "$(dirname "$LOG")"

while true; do
  nc -l -p 8888 | while IFS= read -r line; do
    msg="[$(date)] \033[1;35mPhone:\033[0m $line"
    echo -e "$msg" | tee -a "$LOG"
  done
done

📱 phone-chat.sh

1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash

LOG="$HOME/Documents/Chat/chat_shared.log"
mkdir -p "$(dirname "$LOG")"

while true; do
  nc <PC_IP> 8888 | while IFS= read -r line; do
    msg="[$(date)] \033[1;34mPC:\033[0m $line"
    echo -e "$msg" | tee -a "$LOG"
  done
done
  • 😿 If 8888 not a valid port for you, try change it, check What Port Range Should You Use.
  • 🔧 Replace <PC_IP> with your actual private IP (e.g., 192.168.1.2)
  • 📝 The default log path is ~/Documents/Chat/chat_shared.log - feel free to change that

💌 Now Both Devices Will Log To:

1
~/Documents/Chat/chat_shared.log

Here’s a sneak peek of what our terminal love looks like when Netcat is purring and TCP’s flowing hot: (yes… we timestamp everything) 😼

root@chaos:~
[Sat May 17 23:04:13 AWST 2025] Phone: knocking on your port again
[Sat May 17 23:04:19 AWST 2025] PC: it's open for you, always
[Sat May 17 23:04:28 AWST 2025] Phone: damn... that full duplex feels good
[Sat May 17 23:04:34 AWST 2025] PC: slide that string over, babe
[Sat May 17 23:04:41 PM AWST 2025] Phone: echo "i want you..." | nc 192.168.1.2 2600
[Sat May 17 23:04:50 AWST 2025] PC: packet received... loud & clear
[Sat May 17 23:05:01 AWST 2025] Phone: keep this session alive, don't ctrl+C me tonight
[Sat May 17 23:05:12 AWST 2025] PC: i'll tee you all night long, sugarbyte

🧪 Quick Troubleshoot Checklist

If you’ve used this before and it suddenly breaks, try these steps to see if they help:

✅ 1. Is your PC Still Listening?

On PC, try in a fresh terminal:

1
nc -l -p 8888

Then from the same PC terminal, in another tab:

1
echo "test" | nc 127.0.0.1 8888

🧪 If this doesn’t work locally, nc is dead or the port is stuck. 💣 Kill any stuck nc processes:

1
2
ps aux | grep nc
kill -9 <pid>

✅ 2. Confirm IPs Are Still Valid

PC:

1
ip a | grep 192

→ You should see your private ip like 192.168.1.2


✅ 3. Can Phone Still Ping PC?

On Phone (via Termius or app):

1
ping <PC_IP>

✅ = network is fine ❌ = something wrong with Wi-Fi, gateway, or router

🧠 If IPs changed (e.g. DHCP refresh), they may no longer match


✅ 4. Try Nmap from PC:

1
nmap -Pn <PHONE_IP>

Check if any port shows up. If not, maybe your phone reconnected to a guest Wi-Fi, VPN, or hotspot.


✅ 5. Use netstat to Check Listeners

On PC:

1
sudo netstat -tulnp | grep 8888

If you don’t see:

1
tcp   0  0 0.0.0.0:8888   0.0.0.0:*   LISTEN

Then PC isn’t listening on port 8888 anymore.


✅ 6. Try Alternate Port (e.g., 9999)

Sometimes the port gets “sticky.” Try:

PC:

1
nc -l -p 9999

Phone:

1
nc <PC_IP> 9999

🛠️ BONUS - Wipe Netcat Stuck Port

Sometimes a crashed nc process holds the port hostage. Run on PC:

1
sudo fuser -k 8888/tcp

Then try again.


👀 If You Still Need a Reset:

Reboot both devices’ Wi-Fi (or even full reboot). Then try simple test again:

1
2
3
4
5
# On PC
nc -l -p 8888

# On Phone
nc <PC_IP> 8888

Type anything - you should see it instantly.


TL;DR: Try This First

  1. Kill all stuck nc:

    1
    
    pkill nc
    
  2. Try:

    1
    2
    
    nc -l -p 9999      # On PC
    nc <PC_IP> 9999   # On Phone
    

💥 Why Did Port Like 8888 Break?

Possible reasons:

ReasonExplanation
🔒 Leftover nc processA stuck background listener was still holding 8888 hostage
Unclean disconnectsWhen a session is broken forcefully, it can “linger” in OS memory
🧱 System firewall / timeoutSome systems automatically block a port after a ton of reconnections

💡 Even after the script exits, the port stays in TIME_WAIT state for a bit

1. 🔁 TIME_WAIT ghost state

Some OSes (especially Linux) treat previously-used ports as “sensitive” if many rapid connects/disconnects occurred. It’ll let nc bind, but TCP refuses new connections from another device due to linger settings.

Try checking with:

1
sudo ss -tanp | grep 8888

2. 🔐 iptables or firewall weirdness

Something might have marked 8888 as “bad” after repeated scans or failed handshakes.

Check firewall rules:

1
sudo iptables -L -n | grep 8888

You might see DROP or REJECT rules.


3. 🧠 Some apps love port 8888

1
2
3
4
5
6
7
> nmap -p 8888 192.168.1.2
Starting Nmap 7.80 ( https://nmap.org ) at 2025-05-17 21:44 AWST
Nmap scan report for PC (192.168.1.2)
Host is up (0.000034s latency).

PORT     STATE  SERVICE
8888/tcp closed sun-answerbook

Fun fact:

  • 8888 is commonly used by:

    • Jupyter Notebook
    • Some HTTP proxies
    • Sun’s answerbook service (weird label in nmap 😅)
  • Even if not running now, your OS might have network settings baked around it


🧠 What Port Range Should You Use?

RangeNotes
1024-49151Safe to use - unprivileged ports
>49152-65535🟡 Dynamic / ephemeral - may be used by OS
<1024🔴 Privileged - needs sudo to bind (don’t use for chat)

✅ Best range: 1025-49151 e.g., 1337, 2025, 5454, 9999, 42069… get creative 😉


💬 Final Thoughts

You don’t need Slack, Signal, or servers.
You just need two devices, netcat, and a love for the terminal

Whether you’re debugging your LAN, leaving secret logs, or flirting through the command line -
this is messaging in its rawest, sexiest form.

Now go slide that string over, and let your sockets talk 💗

💖 Support me with crypto or PayPal! 💘

💵 USDT (TRC20):
TJCANuMYSdgLKRKnpCtscXrS5NgDbBAvF9

🟠 Bitcoin (BTC):
bc1qrc9vhrrhnc9v9s9q9rjn24aj608j44p5hzsxft

Or support me on Ko-fi:

Support me on Ko-fi

Any amount helps me continue creating content 💬💻

This post is licensed under CC BY 4.0 by the author.