Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
939 views
in Technique[技术] by (71.8m points)

ip - Python - specify which internet to use in a code

I am facing an issue with the current project I have:

The basic idea is that I am using a dash app to display a graph on a webpage I made (using dash). To launch the page, I have to run my index.py, which is running great when I am connected to the WIFI.

On the other other hand, I have a python code that pings specific IPs and returns whether the device at the specified IP is online or offline. This requires me to connect a sim dongle which is the only way I can communicate with those IPs. The machines are programmed to communicate with the IP of my dongle.

The issue I have is that the data from the pinging program is the input to my dashboard online. I downloaded an application called Speedify, which allows me to connect to multiple internet connections at once, so far so good. Both internet connections appear.

What I need to do:

I would like to write my ping.py program and specify in it that I want the pinging to go through the dongle gateway and not the WIFI. By default the WIFI takes over as the dongle is a P2P device and thus Speedify thinks it is not active.

Is there a way to add some lines to my code to make sure the pining command is being sent through the gate way I specify?

here is the code to ping:

from pythonping import ping
# get info from file and ping dcus
def pingDCUs(timeout):
    df = readCSV() # get pandas DF
    df.index = df.index + 1 # fix index

    status = []

    for i in range(len(df)):
        ip = df.iloc[i]['ip'] # get ip
        print('pinging:', ip)
        res_list = ping(
            ip,
            size = 10,
            count = 4,
            verbose = True,
            timeout = to,
            )

        status.append('offline' if to == res_list.rtt_avg else 'online') # append depending on result

    return status
question from:https://stackoverflow.com/questions/65952960/python-specify-which-internet-to-use-in-a-code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...