Created
June 10, 2022 17:58
-
-
Save HUMORCE/5def398ab9fcd0d2171295c3ff9817cb to your computer and use it in GitHub Desktop.
Convert BitTorrent Trackers Uri from domain to IP via PowerShell.
This file contains 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
[CmdletBinding()] | |
param ( | |
[Parameter()] | |
[string] | |
$Trackers, | |
[Parameter()] | |
[string] | |
$Server | |
) | |
$re = '^(http|https|udp):\/\/(((([a-z0-9|-]*)\.){1,})[a-z]{2,})' | |
$dns = '1.1.1.1' | |
$output = '' | |
if ($Server) { | |
$dns = $Server | |
} | |
$Trackers.Split("`n") | ForEach-Object { | |
if ($_ -match $re) { | |
$domain = $Matches[2] | |
$result = (Resolve-DnsName -Name $domain -Type A -Server $dns -NoHostsFile).IPAddress | |
if ($result.GetType().Name -eq 'String') { | |
$output += $_.Replace($domain, $result) + "`n`n" | |
} | |
else { | |
$output += $_.Replace($domain, $result[0]) + "`n`n" | |
} | |
} | |
} | |
Write-Output $output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment