Advertisement
illwill

Convert domain to punycode

Mar 24th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function ConvertTo-PunyCode{
  2. [cmdletbinding()][parameter()]param($Data)
  3. (New-object System.Globalization.IdnMapping).GetAscii($Data)
  4. }
  5.  
  6. Function ConvertFrom-PunyCode{
  7. [cmdletbinding()][parameter()]param($Data)
  8. try {
  9. (New-object System.Globalization.IdnMapping).GetUnicode($Data)
  10. } catch {continue;}
  11. }
  12.  
  13. $AlexaTop100 = (irm https://raw.githubusercontent.com/urbanadventurer/WhatWeb/master/plugin-development/alexa-top-100.txt).split("`n")
  14. function Get-IDN {
  15. [cmdletbinding()][parameter()]param($Domain,$ErrorActionPreference = "SilentlyContinue")
  16. $Homoglyphs = @()
  17. [array]$a = @(1072,1235,119886)
  18. [array]$e = @(1013,1077,119890,1213,1108)
  19. [array]$i = @(119894)
  20. [array]$u = @(0352056)
  21. [array]$o = @(1086)
  22. foreach ($entry in $domain){
  23. $a | %{$homoglyphs += New-object -typename 'psobject' -property @{domain=$entry;unicode=$domain.replace("a", [char]::ConvertFromUtf32($_));IDN=""}}
  24. $e | %{$homoglyphs += New-object -typename 'psobject' -property @{domain=$entry;unicode=$domain.replace("e", [char]::ConvertFromUtf32($_));IDN=""}}
  25. $i | %{$homoglyphs += New-object -typename 'psobject' -property @{domain=$entry;unicode=$domain.replace("o", [char]::ConvertFromUtf32($_));IDN=""}}
  26. $u | %{$homoglyphs += New-object -typename 'psobject' -property @{domain=$entry;unicode=$domain.replace("u", [char]::ConvertFromUtf32($_));IDN=""}}
  27. $o | %{$homoglyphs += New-object -typename 'psobject' -property @{domain=$entry;unicode=$domain.replace("o", [char]::ConvertFromUtf32($_));IDN=""}}
  28. }
  29. #$$Homoglyphs.count
  30. $Homoglyphs | %{$_.idn = ConvertTo-PunyCode $_.unicode}
  31. $Homoglyphs = $Homoglyphs | ?{($_.idn -match "xn" ) -and ($_.idn -notmatch "xn--cm-fmc$")}
  32. ($Homoglyphs | group unicode) |%{$_.group}
  33. }
  34.  
  35.  
  36.  #clear
  37.  #$AlexaTop100 | %{get-idn $_} |select domain,unicode,IDN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement