I'm trying to make a python code that will autodetect the IP address of Rhode and Schwarz oscilloscope or any test equipment that is connected to my laptop using Ethernet connection.
The IP address of R&S scope at my work place are always starting by the same two numbers 169.254.X.X but the trick is that the IP address of the scope appears in the arp -a report only when I access the scope using its IP address in my the browser. After that the IP shows up in arp report but before nothing the IP address isn't there.
So I wrote the following piece of code thinking it would work but it doesn't since the IP address is not shown before typing the IP address in URL bar of the browser. My goal is to determine the IP address of the scope just by clicking one button on my computer rather than tapping the touchscreen of the scope to find out what is the IP of the equipment.
import tkinter as tk
import time
import threading
import queue
import subprocess
root = tk.Tk()
root.title("SCPI test")
canvas1 = tk.Canvas(root, width=200, height=140, bg='lightsteelblue2', relief='raised')
canvas1.pack()
q1 = queue.Queue()
q2 = queue.Queue()
def auto_detect_ip(num1, num2, num3, num4):
ping_list = []
ping_ok_list = []
t1 = time.time()
for i in range(num1, num2, -1):
for j in range(num3, num4, -1):
temp = "169.254." + str(i) + "." + str(j)
# temp = "192.168.1.1"
try:
p = subprocess.run(["ping", "-n", "1", temp], stdout=subprocess.PIPE, timeout=float(timeout_value))
# p = subprocess.run(["ping", "-n", "1", temp], stdout=subprocess.PIPE, timeout=0.006)
return_code = p.returncode
print("return_code :", return_code)
if return_code == 0:
print("ip_address :", temp)
ping_ok_list.append(temp)
break
except subprocess.TimeoutExpired:
pass
time.sleep(0.00001)
else:
continue
break
len_list_ping = len(ping_list)
print("len_list_ping :", len_list_ping)
print("ping_ok_list :", ping_ok_list)
t2 = time.time()
print("time :", t2 - t1)
if num4 == 0:
q1.put(ping_ok_list)
else:
q2.put(ping_ok_list)
def launch_thread():
print("scan running")
thread_1 = threading.Thread(target=auto_detect_ip, args=(254, 0, 128, 0))
thread_2 = threading.Thread(target=auto_detect_ip, args=(254, 0, 254, 128))
thread_1.setDaemon(True)
thread_2.setDaemon(True)
thread_1.start()
thread_2.start()
def found_rs_scope():
launch_thread()
ping_ok_list = q1.get() + q2.get
print("IP_list :", ping_ok_list)
My solution was to scan each IP address to find the scope one but since the IP doesn't appear in the arp -a in the prompt before accessing the scope through the browser. So there is no match during the scan and the IP isn't found. I think it should be doable but I just don't know how to do it. Also I would like to be able to find the IP address of the scope without requiring admin rights.
Edit:
I checked the port used by oscilloscope and it is 5025 as bfris mentioned in his answer.