openmv/scripts/examples/09-OpenMV-Boards/01-WiFi-Shield/dns.py

25 lines
629 B
Python

# This work is licensed under the MIT license.
# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# DNS Example
#
# This example shows how to get the IP address for websites via DNS.
import network
import usocket
# AP info
SSID = "" # Network SSID
KEY = "" # Network key
# Init wlan module and connect to network
print("Trying to connect... (may take a while)...")
wlan = network.WINC()
wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK)
# We should have a valid IP now via DHCP
print(wlan.ifconfig())
print(usocket.getaddrinfo("www.google.com", 80)[0][4])