Skip to content

Instantly share code, notes, and snippets.

@kimboslice99
Created February 23, 2024 07:26
Show Gist options
  • Save kimboslice99/190f5e5d1e46b52f751eff44dab47648 to your computer and use it in GitHub Desktop.
Save kimboslice99/190f5e5d1e46b52f751eff44dab47648 to your computer and use it in GitHub Desktop.
Update dbip database
$download_file = "dbip-country-lite-$((Get-Date).ToString('yyyy'))-$((Get-Date).ToString('MM')).mmdb"
$download_url = "https://download.db-ip.com/free/$download_file.gz"
# download latest GeoIP database
Invoke-WebRequest -Uri $download_url -OutFile "$PSScriptRoot\dbip-country-lite.mmdb.gz" -UseBasicParsing
Add-Type -AssemblyName System.IO.Compression.FileSystem
$sourceFileStream = [System.IO.File]::OpenRead("$PSScriptRoot\dbip-country-lite.mmdb.gz")
$destinationFileStream = [System.IO.File]::Create("$PSScriptRoot\dbip-country-lite.mmdb")
$gzipStream = New-Object System.IO.Compression.GzipStream $sourceFileStream, ([System.IO.Compression.CompressionMode]::Decompress)
$gzipStream.CopyTo($destinationFileStream)
# close streams
$gzipStream.Close()
$destinationFileStream.Close()
$sourceFileStream.Close()
Remove-Item "$PSScriptRoot\dbip-country-lite.mmdb.gz"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment