My Device is connected to a router, and i have the IP address and port. now i need a script so that i can connect to that IP Address and port and retrieve the data and display in my computer. The data that my Device sends is XML.
I'm completely new to this. I ran Wireshark and i could see my device is sending data from an ip address, and i can even verify that the data is right.
i just need to get the data out and feed it to a visualisation application.
import socket
# Define the IP address and port
TCP_IP = '192.xx.xx.xx' # Target server's IP address
TCP_PORT = xxxxx
# Create a socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
# Connect to the target server
s.connect((TCP_IP, TCP_PORT))
print(f"Connected to {TCP_IP}:{TCP_PORT}")
# Send an HTTP request
request = b'GET /miners/get?file=BFGMiner-3.99-r.1-win32.zip HTTP/1.1\r\nUser-Agent: MultiMiner/V3\r\nHost: www.multiminerapp.com\r\n\r\n'
s.send(request)
# Receive the response
response = s.recv(1024) # Adjust buffer size as needed
with open("http-response.txt", "wb") as respfile:
respfile.write(response)
except ConnectionRefusedError:
print("Connection refused. Check the server availability.")
except Exception as e:
print(f"An error occurred: {e}")
finally:
s.close()
i have tried using this for now