kivy / kivy-ios

Toolchain for compiling Python / Kivy / other libraries for iOS
https://kivy.org/docs/guide/packaging-ios.html
MIT License
776 stars 240 forks source link

Added `py3dns` recipe #728

Closed Neizvestnyj closed 2 years ago

Neizvestnyj commented 2 years ago

Same as in the android, but I change localhost to 8.8.8.8

from kivy.app import App
from kivy.uix.button import Button

import DNS
import smtplib

class TestApp(App):
    def build(self):
        return Button(text='Get DNS',
                      on_release=lambda *args: print(self.get_dns_host('gmail.com')),
                      )

    @staticmethod
    def get_dns_host(hostname: str, timeout=5):
        valid_host = None
        try:
            DNS.DiscoverNameServers()
            mx_hosts = DNS.mxlookup(hostname, timeout)
            for mx in mx_hosts:
                smtp = smtplib.SMTP()
                try:
                    smtp.connect(mx[1])
                except smtplib.SMTPConnectError:
                    continue  # try the next MX server in list
                else:
                    valid_host = mx[1]
        except Exception as err:
            print(err)

        return valid_host

TestApp().run()

Screenshot 2022-07-09 at 00 07 33

Neizvestnyj commented 2 years ago

Let's wait for the CI to do its jobs, but overall looks good. I'm only worried about forcing users to use 8.8.8.8 without warning them.

Did you checked for alternate solutions? (E.g. Like exposing an API via the ios module?)

If we decide that using the Google DNS is the only feasible and easy way to do it, how about including ´8.8.4.4´ as a fallback?

I dont now how to use ios module for that, but using 8.8.4.4 is a good solution (and easy). For exmaple we try to check 8.8.8.8 using socket, if it does not be used, we switch to 8.8.4.4

Neizvestnyj commented 2 years ago

The CI noticed an issue on PEP8 checks, can you take care of it?

yes, I make new commit with some patch fixes

Neizvestnyj commented 2 years ago

@misl6 How about this check script?

import socket

def check_host(host="8.8.8.8", port=53, timeout=3):
    """
    Host: 8.8.8.8 (google-public-dns-a.google.com)
    OpenPort: 53/tcp
    Service: domain (DNS/TCP)
    """
    try:
        socket.setdefaulttimeout(timeout)
        socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
        return True
    except socket.error as ex:
        return False

host = "8.8.8.8"
if not check_host(host):
    host = "8.8.4.4"
misl6 commented 2 years ago

@misl6 How about this check script?

import socket

def check_host(host="8.8.8.8", port=53, timeout=3):
    """
    Host: 8.8.8.8 (google-public-dns-a.google.com)
    OpenPort: 53/tcp
    Service: domain (DNS/TCP)
    """
    try:
        socket.setdefaulttimeout(timeout)
        socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
        return True
    except socket.error as ex:
        return False

host = "8.8.8.8"
if not check_host(host):
  host = "8.8.4.4"

Isn't defaults['server'] = ['8.8.8.8', '8.8.4.4'] instead of defaults['server'].append('8.8.8.8') enough?

Neizvestnyj commented 2 years ago

['8.8.8.8', '8.8.4.4']

Of course, I dont think about it :)

Neizvestnyj commented 2 years ago

@misl6 Done

Neizvestnyj commented 2 years ago

The automated tests on changed recipes are now failing due to a malformed patch.

2022-07-10T08:59:48.6004950Z   STDERR:
2022-07-10T08:59:48.6005440Z /usr/bin/patch: **** malformed patch at line 13: @@ -50,8 +51,12 @@ defaults= { 'protocol':'udp', 'port':53, 'opcode':Opcode.QUERY,

Can you test it locally and check the patch?

I update patch file. I download this and unpack https://launchpad.net/py3dns/trunk/3.2.1/+download/py3dns-3.2.1.tar.gz

cd py3dns-3.2.1
git init
git add .
git commit -m "test"
# make changes in file
git diff > ios.patch