Coder Social home page Coder Social logo

"Weak Network" error message about inb HOT 3 CLOSED

joshiayush avatar joshiayush commented on August 28, 2024
"Weak Network" error message

from inb.

Comments (3)

3ruce avatar 3ruce commented on August 28, 2024

Instead of using ping as per this code

https://github.com/joshiayush/inb/blob/master/inb/lib/utils/net.py

Why not use wget or curl and download google.com's homepage and then delete the temp file to test the internet e.g.

wget -O inb-test-google-index.html google.com
rm inb-test-google-index.html

inb needs port 80/443 open while ping uses another, non-standard port

from inb.

3ruce avatar 3ruce commented on August 28, 2024

Here's the fix for the problem with pinging not being allowed when running ping 8.8.8.8 and getting this error ping: socket: Operation not permitted, likely caused by using inb in an lxd container or similar...

Find out where the ping package is.It might have a different location. On my Ubuntu 18.04 machine, it is in /bin. Use type -a ping to locate it. Next, verify that it is there and is owned by root and is permed 755 (or similar)

ls -lsa /bin/ping
sudo chmod 4711 /bin/ping

Verify that the fix worked

ls -lsa /bin/ping
ping 8.8.8.8
ping 2600:3c01::f03c:92ff:fe3b:2efa

Via https://askubuntu.com/a/1189359

from inb.

joshiayush avatar joshiayush commented on August 28, 2024

We need to replace the current ping function with the function is_internet_alive() defined below in order to make it platform independent. I guess Python socket will not have any issue with a LXD container.

inb/inb/lib/utils/net.py

Lines 29 to 52 in 57fe58d

def ping(host: str = None) -> bool:
"""Returns True if host (str) responds to a ping request.
Remember that a host may not respond to a ping (ICMP) request even if the host
name is valid.
We avoid 'os.system' calls with 'subprocess.call' to avoid shell injection
vulnerability.
:Args:
- host: {str} Hostname.
:Returns:
- {bool} True if server responds, false otherwise.
"""
if not host:
host = "google.com"
if platform.system().lower() == "windows":
param = "-n"
else:
param = "-c"
command: List[str] = ["ping", param, '1', host]
return subprocess.call(command, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL) == 0

Possible solutions

def is_internet_alive(host: str = '1.1.1.1', port: int = 53, timeout: int = 3) -> bool:
    """Check if Internet Connection is alive and external IP address is reachable.
    
    Args:
        host (string): 1.1.1.1 (DNS servver)
        port (integer): (53/tcp DNS Service).
        timeout (float): timeout in seconds.
    
    Returns:
        True (bool): if external IP address is reachable.
        False (bool): if external IP address is unreachable.
    """
    try:
        socket.setdefaulttimeout(timeout)
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((host, port))
    except OSError as error:
        return False
    else:
        s.close()
    return True

from inb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.