init
This commit is contained in:
commit
c305781e8e
22
README.md
Normal file
22
README.md
Normal file
@ -0,0 +1,22 @@
|
||||
# Netc(h)at
|
||||
> minimalist webchat where the client is any generic netcat implementation
|
||||
|
||||
I saw someone posting about a program like this one,
|
||||
I wondered how hard could it be.
|
||||
Apparently,
|
||||
too easy,
|
||||
so I started pushing for the minimun number of characters
|
||||
with which all initial features keep working.
|
||||
Hence `net_chat.full.py` & `net\_chat.min.py.
|
||||
|
||||
To run the server:
|
||||
```Bash
|
||||
$ python3 net_chat.min.py 12345
|
||||
```
|
||||
|
||||
To join:
|
||||
```Bash
|
||||
$ nc 127.0.0.1 12345
|
||||
```
|
||||
|
||||
That, or have more fun using Tor tunneling.
|
35
netchat.full.py
Executable file
35
netchat.full.py
Executable file
@ -0,0 +1,35 @@
|
||||
#!/bin/python3
|
||||
import socket
|
||||
from sys import argv
|
||||
from signal import signal, SIGINT
|
||||
|
||||
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
socket.bind(('localhost', int(argv[1])))
|
||||
socket.listen(100)
|
||||
socket.setblocking(False)
|
||||
|
||||
signal(SIGINT, lambda a, b: (socket.close(), exit(0)))
|
||||
|
||||
print(f"Listening on {argv[1]}...")
|
||||
|
||||
class User:
|
||||
def __init__(self, i):
|
||||
self.username = "anon" + str((id(self) % 999 + 1))
|
||||
self.socket, _ = i
|
||||
self.socket.settimeout(1)
|
||||
|
||||
users = []
|
||||
|
||||
while True:
|
||||
try:
|
||||
users.append(User(socket.accept()))
|
||||
except BlockingIOError:
|
||||
pass
|
||||
for i in users:
|
||||
try:
|
||||
msg = i.socket.recv(1024)
|
||||
except TimeoutError:
|
||||
continue
|
||||
if msg:
|
||||
for h in users:
|
||||
h.socket.send((i.username + ": " + msg.decode()).encode())
|
20
netchat.min.py
Executable file
20
netchat.min.py
Executable file
@ -0,0 +1,20 @@
|
||||
import sys,signal as S
|
||||
s=__import__("socket").socket()
|
||||
s.bind(("localhost",int(sys.argv[1])))
|
||||
s.listen()
|
||||
s.setblocking(0)
|
||||
S.signal(2,lambda a,b:(s.close(),exit(0)))
|
||||
print(f"Listening on {sys.argv[1]}...")
|
||||
def U(i):
|
||||
i[0].settimeout(1)
|
||||
return ["anon"+str((id("")%999+1)),i[0]]
|
||||
u=[]
|
||||
while 1:
|
||||
try:u+=[(U(s.accept()))]
|
||||
except OSError:pass
|
||||
for i in u:
|
||||
try:
|
||||
m=i[1].recv(1024)
|
||||
if m:
|
||||
for h in u:h[1].send((i[0]+": "+m.decode()).encode())
|
||||
except OSError:pass
|
Loading…
x
Reference in New Issue
Block a user