#๐Ÿ”’ Scripts stopped communicating over 2 PCs

39 messages ยท Page 1 of 1 (latest)

drifting pebble
#

Script running on the SENDING PC:

import socket
from pynput import mouse

# Set the IP address of the receiver PC
RECEIVER_IP = "xx.xx.xx.xx"  # Replace with the receiver's IP
PORT = 5005

def send_message(message):
    # """Send a message to the receiver."""
    with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as client:
        client.sendto(message.encode(), (RECEIVER_IP, PORT))
        print(f"Sent: {message}")

def on_click(x, y, button, pressed):
    # """Send right-click events."""
    if button == mouse.Button.right:
        if pressed:
            send_message("RIGHT_DOWN")
        else:
            send_message("RIGHT_UP")
    elif button == mouse.Button.button8:
        if pressed:
            send_message("SIDE1_DOWN")
        else:
            send_message("SIDE1_UP")
    elif button == mouse.Button.button9:
        if pressed:
            send_message("SIDE2_DOWN")
        else:
            send_message("SIDE2_UP")

# Start listening for right-clicks
with mouse.Listener(on_click=on_click) as listener:
    listener.join()

Script running on the RECIEVING PC:

import socket
import time
import logging
from pynput import mouse, keyboard 
 
logging.getLogger('pynput').setLevel(logging.CRITICAL)
 
# Setup server
HOST = "0.0.0.0"  # Listen on all available interfaces
PORT = 5005       # Port to listen on
 
mouse = mouse.Controller()
 
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as server:
    server.bind((HOST, PORT))
    print(f"Listening on {HOST}:{PORT}")
 
    while True:
        data, addr = server.recvfrom(1024)
        message = data.decode()
 
        if message == "RIGHT_DOWN":
            print(f"Right button pressed from {addr}")
            kb = keyboard.Controller()
            kb.press(keyboard.Key.f9)
        elif message == "RIGHT_UP":
            print(f"Right button released from {addr}")
            kb = keyboard.Controller()
            time.sleep(0.5)
            kb.release(keyboard.Key.f9)
        elif message == "SIDE1_DOWN":
            print(f"BackThumb - DOWN")
            kb = keyboard.Controller()
            time.sleep(0.5)
            kb.press(keyboard.Key.f8)
        elif message == "SIDE1_UP":
            print(f"BackThumb - UP")
            kb = keyboard.Controller()
            time.sleep(0.5)
            kb.release(keyboard.Key.f8)
        elif message == "SIDE2_DOWN":
            print(f"FrontThumb - DOWN")
            kb = keyboard.Controller()
            time.sleep(0.5)
            kb.press(keyboard.Key.f8)
        elif message == "SIDE2_UP":
            print(f"FrontThumb - UP")
            kb = keyboard.Controller()
            time.sleep(0.5)
            kb.release(keyboard.Key.f8)

Both scripts appeared to work fine up until a few weeks ago, but now it doesnt work. I have replaced the IP obviously, but have verified this is right on the receiving PC.

The sending program is working. And sending and printing the messages. The recieving program is not picking them up though.

tender starBOT
#

@drifting pebble

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

dusk wedge
#

have you checked port forwarding or firewall, they not blocking it

drifting pebble
#

i dont know how i could do that, I am on linux

#

I think the port 5555 is open on the firewall on the recieving PC, and it doesn't work on that

dusk wedge
#

linux great!

can do two things,

  1. tcpdump to see if the packet is reaching to the reciever
  2. to allow traffic on port you can use ufw

let me know if you need full command

drifting pebble
#

yes i will need exact commands as i dont know what any of that means

dusk wedge
#

also you can check allowed ports on receiving pc by sudo ufw status

#

okay,

  1. tcpdump -i any host "reciever ip" and port "port" - sending pc
  2. sudo ufw allow 5005/tcp - receiving pc
drifting pebble
#

erm

#

which pc doi run it on?

dusk wedge
#

edited the text

drifting pebble
#

for the recieving PC no problem, but on the sending PC it says "You don't have permission to perform this capture on that device
(socket: Operation not permitted)"

#

when i do tcpdump -i xx.xx.xx.xx [port]

dusk wedge
#

sudo tcpdump -i any host "reciever ip" and port "port"

drifting pebble
#

ok now it says "tcpdump: data link type LINUX_SLL2
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes" on sender PC

dusk wedge
#

cool, now check your scripts and see if reciever is getting the data

drifting pebble
#

nope not being recieved

#

the sender terminal with the tcp dump says:

19:48:40.181656 eno1  Out IP baron-System-Product-Name.home.33921 > 254-ipv4.no-dns-yet.as49375.net.4848: UDP, length 10
19:48:40.341521 eno1  Out IP baron-System-Product-Name.home.58678 > 254-ipv4.no-dns-yet.as49375.net.4848: UDP, length 8
19:49:11.655586 eno1  Out IP baron-System-Product-Name.home.43643 > 254-ipv4.no-dns-yet.as49375.net.4848: UDP, length 10
19:49:11.764782 eno1  Out IP baron-System-Product-Name.home.53488 > 254-ipv4.no-dns-yet.as49375.net.4848: UDP, length 8
^C
4 packets captured
4 packets received by filter
0 packets dropped by kernel
dusk wedge
#

can you run "sudo ufw status" on receiver?

drifting pebble
#

Yeah it shows the rules in there for port 4848 as ALLOW

dusk wedge
#

but you running receiver to accept on 5005 right?

drifting pebble
#

Oh i changed the port on both scripts to 4848 to check if maybe a different port would work, but nope

dusk wedge
drifting pebble
#

it shows "4848" "4848/tcp" "4848 (v6)" and "4848/tcp (v6)" all as Allow status

dusk wedge
#

my bad,

#

it supposed to be udp

sudo ufw allow 4848/udp

drifting pebble
#

nope still doesnt recieved anything

#

and now it has a "4848/udp" allow listing

#

I dont know if relevant but when the recieving script is run, it says "listening on 0.0.0.0:4848" rather than a real IP address

dusk wedge
#

run these on receiver,

sudo ufw reload
sudo netstat -uln | grep 4848

drifting pebble
#

ok so i did that

#

the second command makes it do 0.0.0.0:4848 except the 4848 is in red

dusk wedge
#

is it listening?

drifting pebble
#

idk it just prints that command then goes back to a terminal prompt

#

"udp 0 0 0.0.0.0:4848 0.0.0.0:*"

dusk wedge
#

for a test and short period can you disable the firewall on receiver and see if that works? restart the script too

sudo ufw disable
sudo ufw enable - > after testing

tender starBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.