# Buggy code
def is_lan_address(address, additional_private=None):
    if address.lower().startswith("::ffff:") and "." in address:
        # ipv6 mapped ipv4 address, unmap
        address = address[len("::ffff:") :]

    ip = netaddr.IPAddress(address)
    if ip.is_private() or ip.is_loopback():
        return True

    if additional_private is None or not isinstance(additional_private, (list, tuple)):
        additional_private = []

    subnets = netaddr.IPSet()
    for additional in additional_private:
        try:
            subnets.add(netaddr.IPNetwork(additional))
        except:
            pass

    def to_ipnetwork(address):
        try:
            prefix = address["netmask"]
            if "/" in prefix:
                # v6 notation in netifaces output, e.g. "ffff:ffff:ffff:ffff::/64"
                _, prefix = prefix.split("/")

            addr = address["addr"]
            if "%" in addr:
                # interface comment in netifaces output, e.g. "fe80::457f:bbee:d579:1063%wlan0"
                addr = addr[: addr.find("%")]
            return netaddr.IPNetwork("{}/{}".format(addr, prefix))
        except:
            pass

    for interface in netifaces.interfaces():
        addrs = netifaces.ifaddresses(interface)
        for v4 in addrs.get(socket.AF_INET, ()):
            subnets.add(to_ipnetwork(v4))

        if HAS_V6:
            for v6 in addrs.get(socket.AF_INET6, ()):
                subnets.add(to_ipnetwork(v6))

    if ip in subnets:
        return True

    return False


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/pi/oprint/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/oprint/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/oprint/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/oprint/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/oprint/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/server/views.py", line 404, in index
if plugin.will_handle_ui(request):
File "/home/pi/oprint/lib/python2.7/site-packages/octoprint/plugins/forcelogin/__init__.py", line 29, in will_handle_ui
result = passive_login()
File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/server/util/flask.py", line 531, in passive_login
additional_private=ipCheckTrusted)
File "/home/pi/oprint/local/lib/python2.7/site-packages/octoprint/util/net.py", line 59, in is_lan_address
subnets.add(to_ipnetwork(v6))
File "/home/pi/oprint/local/lib/python2.7/site-packages/netaddr/ip/sets.py", line 293, in add
addr = IPNetwork(addr)
File "/home/pi/oprint/local/lib/python2.7/site-packages/netaddr/ip/__init__.py", line 928, in __init__
implicit_prefix, flags)
File "/home/pi/oprint/local/lib/python2.7/site-packages/netaddr/ip/__init__.py", line 823, in parse_ip_network
raise TypeError('unexpected type %s for addr arg' % type(addr))
TypeError: unexpected type <type 'NoneType'> for addr arg

# Fixed code
def is_lan_address(address, additional_private=None):
    try:
        if address.lower().startswith("::ffff:") and "." in address:
            # ipv6 mapped ipv4 address, unmap
            address = address[len("::ffff:") :]

        ip = netaddr.IPAddress(address)
        if ip.is_private() or ip.is_loopback():
            return True

        if additional_private is None or not isinstance(
            additional_private, (list, tuple)
        ):
            additional_private = []

        subnets = netaddr.IPSet()
        for additional in additional_private:
            try:
                subnets.add(netaddr.IPNetwork(additional))
            except:
                if logging.getLogger(__name__).isEnabledFor(logging.DEBUG):
                    logging.getLogger(__name__).exception(
                        "Error while trying to add additional private network to local subnets: {}".format(
                            additional
                        )
                    )

        def to_ipnetwork(address):
            prefix = address["netmask"]
            if "/" in prefix:
                # v6 notation in netifaces output, e.g. "ffff:ffff:ffff:ffff::/64"
                _, prefix = prefix.split("/")

            addr = address["addr"]
            if "%" in addr:
                # interface comment in netifaces output, e.g. "fe80::457f:bbee:d579:1063%wlan0"
                addr = addr[: addr.find("%")]
            return netaddr.IPNetwork("{}/{}".format(addr, prefix))

        for interface in netifaces.interfaces():
            addrs = netifaces.ifaddresses(interface)
            for v4 in addrs.get(socket.AF_INET, ()):
                try:
                    subnets.add(to_ipnetwork(v4))
                except:
                    if logging.getLogger(__name__).isEnabledFor(logging.DEBUG):
                        logging.getLogger(__name__).exception(
                            "Error while trying to add v4 network to local subnets: {!r}".format(
                                v4
                            )
                        )

            if HAS_V6:
                for v6 in addrs.get(socket.AF_INET6, ()):
                    try:
                        subnets.add(to_ipnetwork(v6))
                    except:
                        if logging.getLogger(__name__).isEnabledFor(logging.DEBUG):
                            logging.getLogger(__name__).exception(
                                "Error while trying to add v6 network to local subnets: {!r}".format(
                                    v6
                                )
                            )

        if ip in subnets:
            return True

        return False

    except:
        # we are extra careful here since an unhandled exception in this method will effectively nuke the whole UI
        logging.getLogger(__name__).exception(
            "Error while trying to determine whether {} is a local address".format(
                address
            )
        )
        return True