Jump to content

As part of a project I'm working on, I need a python script to be able to send data through the network to a receiving server script on another computer. Currently, when the client script attempts to send the keypress to the server, a "ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine" error occurs. I know this is the firewall but it's not like I have a program that can be added to the firewall to allow the connection. I must admit I am very new to working with powershell so help would be appreciated. :)

PC Specs:

CPU: AMD 1700x Cooler: Corsair H100i V2 Motherboard: Asus Crosshair VI Hero RAM: 4 * 8GB G.Skill RGB DDR4 Graphics: EVGA GTX 1080 Ti SC2 Storage: Samsung 960 EVO 500GB Case: Fractal Design Meshify C PSU: EVGA 750w G3 Monitors: Dell SG2716DG +  2x Dell U2515H

 

Freenas specs:

CPU: Intel Xeon E5-2650 V2 Cooler: Some noctua cooler Motherboard: Supermicro X9 SRL-F RAM: 8 * 8GB Samsung DDR3 ECC Storage: 6 * 4TB Seagate 7200 RPM RAIDZ2 Controller: LSI H220 Case: Phanteks Enthoo Pro PSU: EVGA 650w G3

 

Phone: iPhone 6S 32 GB Space Grey

Link to comment
https://linustechtips.com/topic/922259-python-powershell-windows-firewall-issue/
Share on other sites

Link to post
Share on other sites

I just want clear up something: you say you're sending data and then saying you're sending a keypress to the secondary machine, are you trying to remotely access the secondary machine from your first machine?

 

Are you setting up a TCP connection between both machines? Is the server set up to sit in a "waiting" loop until instructions are received? Is the data sent by the client to the server actually readable by the server (as in, did you set the server to correctly receive the data?)

 

I did this kind of stuff in C/C++, and for the most part this is all that's needed. If you're trying to send an actual keypress to the server, and thus make the server register a keypress on the keyboard, then this might need more work to actually do that.

Link to post
Share on other sites

1 hour ago, HunterAP said:

I just want clear up something: you say you're sending data and then saying you're sending a keypress to the secondary machine, are you trying to remotely access the secondary machine from your first machine?

 

Are you setting up a TCP connection between both machines? Is the server set up to sit in a "waiting" loop until instructions are received? Is the data sent by the client to the server actually readable by the server (as in, did you set the server to correctly receive the data?)

 

I did this kind of stuff in C/C++, and for the most part this is all that's needed. If you're trying to send an actual keypress to the server, and thus make the server register a keypress on the keyboard, then this might need more work to actually do that.

I'll give some more details. My uncle and I are currently working on a join project so he wrote this code (though I generally understand what it's doing). My task is to port this python code to a C# console app. The server will wait to accept the data sent from the client, at least in theory.

 

Server:

Spoiler

#!/usr/bin/python           # This is server.py file

import socket               # Import socket module

s = socket.socket()         # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345                # Reserve a port for your service.
s.bind((host, port))        # Bind to the port

test = ''

s.listen(5)                 # Now wait for client connection.
c, addr = s.accept()
while test != b'q':
   test = c.recv(1024)
   print(test)
c.close()                # Close the connection

Client:

Spoiler

#!/usr/bin/python           # This is client.py file

import socket               # Import socket module
import sys
import msvcrt

s = socket.socket()         # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345               # Reserve a port for your service.
if len(sys.argv) > 1:
    port = int(sys.argv[1])

s.connect((host, port))
test = ''
while test != b'q':
        test = msvcrt.getch()
        s.send(test)
s.close                     # Close the socket when done

 

PC Specs:

CPU: AMD 1700x Cooler: Corsair H100i V2 Motherboard: Asus Crosshair VI Hero RAM: 4 * 8GB G.Skill RGB DDR4 Graphics: EVGA GTX 1080 Ti SC2 Storage: Samsung 960 EVO 500GB Case: Fractal Design Meshify C PSU: EVGA 750w G3 Monitors: Dell SG2716DG +  2x Dell U2515H

 

Freenas specs:

CPU: Intel Xeon E5-2650 V2 Cooler: Some noctua cooler Motherboard: Supermicro X9 SRL-F RAM: 8 * 8GB Samsung DDR3 ECC Storage: 6 * 4TB Seagate 7200 RPM RAIDZ2 Controller: LSI H220 Case: Phanteks Enthoo Pro PSU: EVGA 650w G3

 

Phone: iPhone 6S 32 GB Space Grey

Link to post
Share on other sites

I don't believe you need to reserve the port on the client program, that's something you only do on the server program, where the client then sends a connection request to that IP address and port.

 

According to the Python docs page for the Socket module, your uncle should've done something like this is in his python client program:

def mysend(self, msg):
        totalsent = 0
        while totalsent < MSGLEN:
            sent = self.sock.send(msg[totalsent:])
            if sent == 0:
                raise RuntimeError("socket connection broken")
            totalsent = totalsent + sent

As for C#, I would recommend looking at these documents that show how to implement a socket connection between a client and a server.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×