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 =
usersaddr =
number = 0
usernames =
if os.path.exists("chatlogs.txt") == False:
f = open("chatlogs.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:
isock.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.AFINET, socket.SOCKSTREAM)
s.setsockopt(socket.SOLSOCKET, 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.startnewthread(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!!
Comments
No Comments Exist
Be the first, drop a comment!