How to detect if the internet connection is over WiFi or Ethernet?

internet speed test
how to check what type of internet connection you have
check internet connection stability
how to check ethernet speed on mac
internet connection consistency test
how to check if my internet connection is stable
internet speed calculator

Is there a way to open network settings programmatically? Closest thing I know is opening the main settings page:

let settingsURL = NSURL(string: UIApplicationOpenSettingsURLString)!

I want to be able to detect if the internet connection is over WiFi or Ethernet.

The way to detect this is to look at the name of the network interfaces. For Mac and Apple TV, en0 and en1 refer to the wired and wireless interfaces respectively.

Add this to your bridging header (or create one if needed):

#include <ifaddrs.h>
#include <net/if_dl.h>

Then use this Swift code to get the information you need:

struct Networking {

    enum NetworkInterfaceType: String, CustomStringConvertible {
        case Ethernet = "en0"
        case Wifi = "en1"
        case Unknown = ""

        var description: String {
            switch self {
            case .Ethernet:
                return "Ethernet"
            case .Wifi:
                return "Wifi"
            case .Unknown:
                return "Unknown"

    static var networkInterfaceType: NetworkInterfaceType {
        if let name = Networking().getInterfaces().first?.name, let type = NetworkInterfaceType(rawValue: name) {
            return type

        return .Unknown

    static var isConnectedByEthernet: Bool {
        let networking = Networking()
        for addr in networking.getInterfaces() {
            if == NetworkInterfaceType.Ethernet.rawValue {
                return true
        return false

    static var isConnectedByWiFi: Bool {
        let networking = Networking()
        for addr in networking.getInterfaces() {
            if == NetworkInterfaceType.Wifi.rawValue {
                return true
        return false

    // Credit to Martin R for this lovely code
    // New Swift 3 implementation needed upated to replace unsafepointer calls with .withMemoryRebound
    func getInterfaces() -> [(name : String, addr: String, mac : String)] {

        var addresses = [(name : String, addr: String, mac : String)]()
        var nameToMac = [ String: String ]()

        // Get list of all interfaces on the local machine:
        var ifaddr : UnsafeMutablePointer<ifaddrs>?
        guard getifaddrs(&ifaddr) == 0 else { return [] }
        guard let firstAddr = ifaddr else { return [] }

        // For each interface ...
        for ptr in sequence(first: firstAddr, next: { $0.pointee.ifa_next }) {
            let flags = Int32(ptr.pointee.ifa_flags)
            if var addr = ptr.pointee.ifa_addr {
                let name = String(cString: ptr.pointee.ifa_name)

                // Check for running IPv4, IPv6 interfaces. Skip the loopback interface.
                if (flags & (IFF_UP|IFF_RUNNING|IFF_LOOPBACK)) == (IFF_UP|IFF_RUNNING) {
                    switch Int32(addr.pointee.sa_family) {
                    case AF_LINK:
                        nameToMac[name] = withUnsafePointer(to: &addr) { unsafeAddr in
                            unsafeAddr.withMemoryRebound(to: sockaddr_dl.self, capacity: 1) { dl in
                                dl.withMemoryRebound(to: Int8.self, capacity: 1) { dll in
                                    let lladdr = UnsafeRawBufferPointer(start: dll + 8 + Int(dl.pointee.sdl_nlen), count: Int(dl.pointee.sdl_alen))

                                    if lladdr.count == 6 {
                                        return { String(format:"%02hhx", $0)}.joined(separator: ":")
                                    } else {
                                        return nil

                    case AF_INET, AF_INET6:
                        // Convert interface address to a human readable string:
                        var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
                        if (getnameinfo(addr, socklen_t(addr.pointee.sa_len),
                                        &hostname, socklen_t(hostname.count),
                                        nil, socklen_t(0), NI_NUMERICHOST) == 0) {
                            let address = String(cString: hostname)
                            addresses.append( (name: name, addr: address, mac : "") )


        // Now add the mac address to the tuples:
        for (i, addr) in addresses.enumerated() {
            if let mac = nameToMac[] {
                addresses[i] = (name:, addr: addr.addr, mac : mac)

        return addresses

Usage is:



switch Networking.networkInterfaceType {
case .Ethernet:
    // do something

case .Wifi:
    // do something else


How to Determine What Kind of Internet Connection You Have , High-speed Internet, as the name indicates, should be faster than dial-up, but line to a wired or wireless network -- or to no network at all -- and then check your modem via a network cable; if you're connected via Wi-Fi, search the inside of� Under the "Properties" section, find the network adapter (Wi-Fi or Ethernet). Determine the connection speed in the Link speed (Receive/Transmit) field. Source: Windows Central. Once you complete

For iOS 12.0+, tvOS 12.0+, macOS 10.14+ and watchOS 5.0+ apps you can use NWPathMonitor to solve the problem that you described in your question. Add this code to your application(_:didFinishLaunchingWithOptions:) implementation (Swift 5.1.3/Xcode 11.3.1):

let pathMonitor = NWPathMonitor()
pathMonitor.pathUpdateHandler = { path in
    if path.status == .satisfied {
        if path.usesInterfaceType(.wifi) {
        } else if path.usesInterfaceType(.cellular) {
        } else if path.usesInterfaceType(.wiredEthernet) {
        } else if path.usesInterfaceType(.loopback) {
        } else if path.usesInterfaceType(.other) {
    } else {
        print("not connected")
pathMonitor.start(queue: .global(qos: .background))

And don't forget to add import Network to the top of the file.

How to check up and fix your internet connection, For example, if your Wi-Fi Access Point (AP), cable, or DSL modem are Check to see if you can connect to your AP using an Ethernet cable� For instance, if your Wi-Fi connection isn't working, check that your PC is trying to connect to the right AP. If your device is attempting to hook up to your old, retired AP, you're not going to

You can use Reachability API.

let reachability: Reachability = Reachability.reachabilityForInternetConnection()
(reachability.currentReachabilityStatus().value == ReachableViaWiFi.value) // For WiFi
(reachability.currentReachabilityStatus().value == ReachableViaWWAN.value) // For WWAN
(reachability.currentReachabilityStatus().value == NotReachable.value) // For No Internet

How to determine Wi-Fi and Ethernet connection speed on Windows , If you're upgrading your internet service to a faster tier, knowing the maximum� An internet speed test measures the connection speed and quality of your connected device to the internet. It does so by running multiple consecutive tests that analyze different aspects of your internet connection, namely ping (latency), download speed, and upload speed.

How to tell whether your computer is using wifi or ethernet to access , 2 Answers. Show activity on this post. If you use the command route there will be and entry in the table with the value 'Default' or '0.0. 0.0' as destination field, then the 'Iface' field will be the interface (Ethernet or wifi) your computer is using to reach the internet. If Wi-Fi is disabled and you’re still not getting a network connection, make sure that ethernet is enabled in the same Network and Internet Settings section. Find the right network. It will likely

Wi-Fi vs. Ethernet: Which Connection to Use?, You can also use Ethernet from WiFi. Or do you think that traditional wired cable connections will continue being used to go online? Check out Ubidots STEM, our 100% FREE platform made specifically for non-commercial use. WiFi is a wireless technology that connects devices to the internet without� There is a lot of debate about Wi-Fi speeds and whether they can offer higher potential speeds than a cable connection, but in practice Ethernet connections turn out to be not only faster but also

How to Detect if Someone's Stealing Your WiFi, Can you detect if someone is stealing your WiFi? Thanks to the ubiquity of wireless routers and hotspots, just about any plain old wired Internet connection A wireless network is comprised of a broadband Internet connection from a DSL,� When you connect an Ethernet cable to a Windows 10 computer, it automatically connects to the internet using Ethernet connection, instead of using the WiFi Network. However, the WiFi network still remains open on your computer and you will have to manually turn off the WiFi Network, in case you do not want both WiFi and Ethernet being active on

  • Could you provide a swift 3 update? There are some issues with the UnsafePointer parts
  • Reachability has no value for Ethernet. It returns ReachableViaWiFi for it instead. I think ReachableViaWiFi should be renamed to ReachableViaLAN or something in this case.
  • I agree with @saucewipe . Reachability is not detecting the difference between WiFi and Ethernet.
  • Which modules do I have to import for using Reachability in Swift?
  • You'll have to download and setup Reachability for use from Apple, or else write your own implementation yourself (it's not super tricky -- and there are many on GitHub). I concur with the above comments -- Reachability cannot separate ethernet from wlan, it just tells you wether you're on a wwan connection or not.