Forum Thread: How to Make a Multi-User Chat Program for Hackers

Have you ever felt alone in the place and felt like there are no hackers amongst you? Do you go to Star Bucks and feel like "If there was someone here with me hacking all these people like Aiden Pearce(you should play Watch_Dogs if you haven't...)"? Well, I have too...So i created a chat program that lets anyone who figures "hey...lemme hack the people here" to find hacker buddies....lol...

It's just a chat program, so nothing special...hehehe...

Here is the code:

import socket, os
import thread, time

userssocks =
users
addr =
number = 0
usernames =

if os.path.exists("chatlogs.txt") == False:
f = open("chat
logs.txt", "w")
f.close()

def usernamethreader(sock, addr):
sock.send("*WELCOME TO THIS CHAT PROGRAM!!\n(If this is a hack attempt then you are among friends :D)\n")
sock.send("*Simply close your shell to terminate the program")
sock.send("\n*As at now, there are %d number of users" %number)

sock.send("\n*If you happen to be the only one here and feel like leaving but want to keep in touch, leave something so that we can contact you!")

while True:
try:
sock.send("\n+What is your username: ")
name = sock.recv(1024)
if name in usernames:
sock.send("\n*Username already exists!!")
else:
break
except:
pass

usernames.append(name)
recvMsg(sock, addr, name)

def recvMsg(sock, addr, username):
while True:
try:
data = sock.recv(4096)

msg = username.strip() + ":" + str(data.strip())
for isock in userssocks:
i
sock.send(msg+"\n")

g.write(msg+"\n")

except:
sock.close()
usernames.remove(username)
usersaddr.remove(addr)
continue

def connections():
os.system("clear")
for addrs in usersaddr:
print "*Connection from %s" %str(addrs)
time.sleep(3)

g = open("chatlogs.txt", "a")
g.write(time.strftime('-'15+' %Y-%m-%d %H:%M:%S '+'-'15))
s = socket.socket(socket.AF
INET, socket.SOCKSTREAM)
s.setsockopt(socket.SOL
SOCKET, socket.SOREUSEADDR, 1)

s.bind(('', 9000))

s.listen(10)

while True:
try:
conn, addr = s.accept()
userssocks.append(conn)
usersaddr.append(addr)
number+=1
print "* Connection from %s" %str(addr)
thread.start
newthread(usernamethreader, (conn, addr,))
thread.startnewthread(connections, ())
except socket.timeout:
pass

except KeyboardInterrupt:
break

g.close()

The format might not have come out right...click this link if you want.

Happy New Year guys...

Wuzi out!!

6 Responses

This is python 2.7 right?

Neat script. Happy new year to you too!

Thanks a lot...

Hey, thanks for the great article and script. I was just wondering how I could connect to this. Is there a port opened automatically, and of so, which one? Will netcat work, or do I need to SSH my way in?

Any help will be appreiated.

Ninja243

:Edit:
I just found that it opens port 9000. Thanks for the script once again :D

You welcome...and yes netcat will work :D

Wuzi out

Share Your Thoughts

  • Hot
  • Active