Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if INTERACTIVE
- #r "System.Net.Http.dll"
- #endif
- let publicSuffixList =
- let url = "https://publicsuffix.org/list/public_suffix_list.dat"
- use httpClient = new System.Net.Http.HttpClient()
- let text = httpClient.GetStringAsync(url).Result
- let lines = text.Split('\n')
- lines
- |> Array.filter (fun line -> not(System.String.IsNullOrWhiteSpace line))
- |> Array.filter (fun line -> not(line.StartsWith "//"))
- |> Array.filter (fun line -> not(line.StartsWith "!"))
- |> Array.map (fun line -> if line.StartsWith "*." then line.Substring 2 else line)
- |> Array.map (fun suffix -> "." + suffix.Trim())
- |> Array.sortByDescending (fun text -> text.Length)
- let suffix (host:string) =
- publicSuffixList |> Array.tryFind (fun suffix -> host.EndsWith suffix)
- let registeredName (url:string) =
- let uri = System.Uri(url,System.UriKind.Absolute)
- let host = uri.Host
- match suffix host with
- | Some suffix ->
- let name = host.Substring(0,host.Length-suffix.Length)
- match name.LastIndexOf('.') with
- | -1 -> Some name
- | index -> Some(name.Substring(index+1))
- | None -> None
- suffix "austin.rr.com" // -> Some ".com"
- suffix "hotmail.co.jp" // -> Some ".co.jp"
- suffix "yahoo.com.br" // -> Some ".com.br"
- suffix "prodigy.net.mx" // -> Some ".net.mx"
- suffix "alum.mit.edu" // Some ".edu"
- registeredName "http://www.idtechex.com" // -> Some "idtechex"
- registeredName "http://wilderblog.azurewebsites.net" // -> Some "wilderblog"
- registeredName "http://www.eng.cam.ac.uk/" // -> Some "cam"
- registeredName "http://web.mit.edu/facts/academic.html" // -> Some "mit"
- registeredName "http://www.research.ibm.com/quantum/" // -> Some "ibm"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement