Skip to content

Instantly share code, notes, and snippets.

@jamescoxon
Created August 13, 2019 22:41
Show Gist options
  • Select an option

  • Save jamescoxon/972a17c04e9376e15530b1b63e95ea18 to your computer and use it in GitHub Desktop.

Select an option

Save jamescoxon/972a17c04e9376e15530b1b63e95ea18 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import socket
import traceback
import time
TCP_IP = '138.201.94.249'
TCP_PORT = 7075
BUFFER_SIZE = 128
byte_message = bytearray( [ 0x52, 0x43, 0x11, 0x11, 0x0d, 0x02, 0x00, 0x00 ] )
first_ipaddress_bytes = bytearray ( [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa3, 0x1b ])
ipaddress_bytes = bytearray ( [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ])
interval_sec = 10
s = socket.create_connection((TCP_IP, TCP_PORT))
total_message = bytearray(b'').join([byte_message, first_ipaddress_bytes])
for x in range(7):
total_message = bytearray(b'').join([total_message, ipaddress_bytes])
s.send(total_message)
while True:
try:
data = s.recv(BUFFER_SIZE)
if len(data) > 0:
print(data)
except:
traceback.print_exc()
print('Other Socket err, exit and try creating socket again')
# break from loop
break
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment