Skip to content

Instantly share code, notes, and snippets.

@HUMORCE
Created June 10, 2022 17:58
Show Gist options
  • Save HUMORCE/5def398ab9fcd0d2171295c3ff9817cb to your computer and use it in GitHub Desktop.
Save HUMORCE/5def398ab9fcd0d2171295c3ff9817cb to your computer and use it in GitHub Desktop.
Convert BitTorrent Trackers Uri from domain to IP via PowerShell.
[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