dagrha / pypia

Configuration of Private Internet Access VPN routes for Linux
GNU General Public License v3.0
78 stars 15 forks source link

Not able to ping all servers #29

Closed LarsNorgaard closed 5 years ago

LarsNorgaard commented 6 years ago

Seems like I'm only able to ping and list the US servers and not the rest?

Exception in thread Thread-25:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pypia/pypia.py", line 272, in ping
    result = subprocess.check_output(['ping', '-c', '3', ip]).decode('utf-8')
  File "/usr/lib/python3.5/subprocess.py", line 626, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.5/subprocess.py", line 708, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['ping', '-c', '3', '31.168.172.142']' returned non-zero exit status 1

Exception in thread Thread-22:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.5/dist-packages/pypia/pypia.py", line 272, in ping
    result = subprocess.check_output(['ping', '-c', '3', ip]).decode('utf-8')
  File "/usr/lib/python3.5/subprocess.py", line 626, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.5/subprocess.py", line 708, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['ping', '-c', '3', '108.61.122.217']' returned non-zero exit status 1
dagrha commented 6 years ago

Hi Lars,

You can specify a region with the -r flag-- the options are us, int (for non-US), and all. pypia uses US by default. As an example, you could do:

pypia -r all -p

which should tabulate the average of 3 pings to each pia server worldwide.

I'm not sure about those exceptions-- can you tell me more about those?

Thanks

LarsNorgaard commented 6 years ago

Yeah, but when I run that command I get those errors. Works fine if I ping the US servers. Could it be that some of the servers are down, so the script gets an 404 and errors out?

dagrha commented 6 years ago

Interesting. That's possible. I will look into it this evening. Thanks for reporting it!

dagrha commented 6 years ago

I have not been able to reproduce the error. Are you able to ping those IP addresses directly? In other words, from the terminal, for example ping 108.61.122.217

LarsNorgaard commented 6 years ago

Just tried pinging some of the IP's and some packet loss is happening. Guess it could be my network or my router borking up.

--- 177.154.139.203 ping statistics ---
22 packets transmitted, 20 received, 9% packet loss, time 21052ms
rtt min/avg/max/mdev = 239.779/240.049/240.334/0.266 ms

Not too sure if that could be why I get those python errors?

dagrha commented 6 years ago

Might be-- in any case I should probably add some code to deal with uncooperative endpoints so that the program doesn't error out when there's a problem pinging one of the servers.

Saltani commented 5 years ago

I have had the same problem. I live in Denmark and primarily uses european servers. Using pypia -r int -f or pypia -r int -p causes pypia to crash, if one of the servers are down. I solved it by adding a few lines of code to the ping method in the latencies class so the ping method now looks like this:

    def ping(self):
        ip = self.q.get()
        try:
            result = subprocess.check_output(['ping', '-c', '3', ip]).decode('utf-8')
        except subprocess.CalledProcessError:
            self.q.task_done()
            return
        avg = float(result.split('=')[-1].split('/')[1])
        self.latencies[ip] = avg
        self.q.task_done()

I'm sure it can be done more eleganly, but it works for me. /Saltani

dagrha commented 5 years ago

@Saltani, this is great, thank you for debugging and submitting a workaround. I like the try/except to catch the CalledProcessError exception.

One thing I'd like to do is somehow notify the user that one of the endpoints failed. I think what I'll do instead of marking self.q.task_done() in the except block, I'll assign the avg for that ip to an arbitrarily high latency time, so that it is obvious that the ping failed for that endpoint, and so it will still get recorded in the latencies table.

dagrha commented 5 years ago

fixed with 6099c5efb99f46c287721d4cb0381f1d658dd247

updated version on pypi to 0.3.6

Saltani commented 5 years ago

Good solution. Works nicely, thanks a lot :-)

image