This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func reverseDNS(ip: String) -> String { | |
var results: UnsafeMutablePointer<addrinfo>? = nil | |
defer { | |
if let results = results { | |
freeaddrinfo(results) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Needs to be run on async otherwise you will get a crash. | |
// Make sure you have the internet permission added to the app manifest if this is going in an Anrdoid app... | |
<uses-permission android:name="android.permission.INTERNET" /> | |
public class DnsLookup extends AsyncTask<ArrayList<String>, Integer, ArrayList<HostIpDetails>> { | |
private static String TAG = "DnsLookup"; | |
public interface DnsLookUpCompletionListener { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// You many want to run this in the background | |
func getIPs(dnsName: String) -> String? { | |
let host = CFHostCreateWithName(nil, dnsName as CFString).takeRetainedValue() | |
CFHostStartInfoResolution(host, .addresses, nil) | |
var success: DarwinBoolean = false | |
if let addresses = CFHostGetAddressing(host, &success)?.takeUnretainedValue() as NSArray? { | |
for case let theAddress as NSData in addresses { | |
var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST)) |