title: How to get ipaddress when connected to mobile data swift3
body: <p>I am getting ipaddress of the phone in this way.</p>
  
  <pre><code>func getIPAddress() -&gt; String? {
      var address : String?
  
      var ifaddr : UnsafeMutablePointer&lt;ifaddrs&gt;? = nil
      if getifaddrs(&amp;ifaddr) == 0 {
  
          var ptr = ifaddr
          while ptr != nil {
              defer { ptr = ptr?.pointee.ifa_next }
  
              let interface = ptr?.pointee
  
              let addrFamily = interface?.ifa_addr.pointee.sa_family
              if addrFamily == UInt8(AF_INET) || addrFamily == UInt8(AF_INET6) {
  
                  if let name:String = String(cString: (interface?.ifa_name)!), name == "en0" {
  
                      var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
                      getnameinfo(interface?.ifa_addr, socklen_t((interface?.ifa_addr.pointee.sa_len)!),
                                  &amp;hostname, socklen_t(hostname.count),
                                  nil, socklen_t(0), NI_NUMERICHOST)
                      address = String(cString: hostname)
                  }
              }
          }
          freeifaddrs(ifaddr)
      }
  
      return address
  }
  </code></pre>
  
  <p>But this returns when connected to wifi only. How to get ipaddress when I connected to mobile data.</p>