socket.gethostbyaddr #18026
Unanswered
verasativa
asked this question in
Using MicroPython
Replies: 4 comments 3 replies
|
Hi |
1 reply
|
Ah ok! Hope that help you |
0 replies
|
Are you a bot? |
2 replies
|
Micropython only has socket.getaddrinfo; it does not have any others. You need to implement socket.gethostbyaddr using a low-level UDP DNS query on port 53 to a DNS server. Alternatively, you can use the web API. # dns_web_api.py
import time
import wifi # connect to your wifi
time.sleep(5)
import requests
def reverse_ip_to_ptr(ip):
return '.'.join(ip.split('.')[::-1]) + '.in-addr.arpa'
# Forward DNS lookup example
domain = 'one.one.one.one'
print(domain)
forward_url = f'https://dns.google/resolve?name={domain}&type=A'
resp = requests.get(forward_url)
forward_data = resp.json()
print(forward_data['Answer'])
# Reverse DNS lookup example
ip = '1.1.1.1'
print(ip)
rev_ip = reverse_ip_to_ptr(ip)
reverse_url = f'https://dns.google/resolve?name={rev_ip}&type=PTR'
resp = requests.get(reverse_url)
reverse_data = resp.json()
print(reverse_data['Answer']) |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi, how should I replace the socket.gethostbyaddr function from full python? (I'm running a hotspot and a wifi client networks)
All reactions