title: Swift - Get device's WIFI IP Address
body: <p>I need to get IP Address of iOS device in Swift. This is not a duplicate of other questions about this! I need to get only WiFi IP address, if there is no wifi ip address - I need to handle it. There are a few questions about it on Stack Overflow, but there are only functions that return ip addresses. For example (from <a href="https://stackoverflow.com/questions/25626117/how-to-get-ip-address-in-swift/25627545#25627545">How to get Ip address in swift</a>):</p>
  
  <pre><code>func getIFAddresses() -&gt; [String] {
      var addresses = [String]()
  
      // Get list of all interfaces on the local machine:
      var ifaddr : UnsafeMutablePointer&lt;ifaddrs&gt; = nil
      if getifaddrs(&amp;ifaddr) == 0 {
  
          // For each interface ...
          for (var ptr = ifaddr; ptr != nil; ptr = ptr.memory.ifa_next) {
              let flags = Int32(ptr.memory.ifa_flags)
              var addr = ptr.memory.ifa_addr.memory
  
              // Check for running IPv4, IPv6 interfaces. Skip the loopback interface.
              if (flags &amp; (IFF_UP|IFF_RUNNING|IFF_LOOPBACK)) == (IFF_UP|IFF_RUNNING) {
                  if addr.sa_family == UInt8(AF_INET) || addr.sa_family == UInt8(AF_INET6) {
  
                      // Convert interface address to a human readable string:
                      var hostname = [CChar](count: Int(NI_MAXHOST), repeatedValue: 0)
                      if (getnameinfo(&amp;addr, socklen_t(addr.sa_len), &amp;hostname, socklen_t(hostname.count),
                          nil, socklen_t(0), NI_NUMERICHOST) == 0) {
                              if let address = String.fromCString(hostname) {
                                  addresses.append(address)
                              }
                      }
                  }
              }
          }
          freeifaddrs(ifaddr)
      }
  
      return addresses
  }
  </code></pre>
  
  <p>Here I get 2 values - address from mobile internet(I think) and WiFi address I need. Is there any other way to get ONLY WiFi IP Address?</p>