openmv/scripts/examples/09-WiFi/dns.py
iabdalkader 0101917e0e scripts/examples: Refactor WiFi and Bluetooth examples.
Unified set of examples for all WiFi/BT modules.
2023-10-28 17:25:57 +02:00

28 lines
712 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 time
import socket
SSID = "" # Network SSID
KEY = "" # Network key
# Init wlan module and connect to network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, KEY)
while not wlan.isconnected():
print('Trying to connect to "{:s}"...'.format(SSID))
time.sleep_ms(1000)
# We should have a valid IP now via DHCP
print("WiFi Connected ", wlan.ifconfig())
print(socket.getaddrinfo("www.google.com", 80)[0][4])