Skip to content

Instantly share code, notes, and snippets.

@3xploiton3
Created December 16, 2025 07:23
Show Gist options
  • Select an option

  • Save 3xploiton3/9fffe309946642a5691b4f5fcc9094ad to your computer and use it in GitHub Desktop.

Select an option

Save 3xploiton3/9fffe309946642a5691b4f5fcc9094ad to your computer and use it in GitHub Desktop.
Cek IP berbagai layanan menggunakan powershell di windows 11
# 1. Daftar layanan yang diperkaya dengan informasi endpoint GeoIP
# Setiap layanan kini mendefinisikan cara mengambil IP dan data Geo-nya sendiri.
$services = @(
# Layanan dengan endpoint JSON untuk GeoIP
@{ Name="ipinfo.io"; Cmd4="curl -4 -s --max-time 5 ipinfo.io/ip"; Cmd6="curl -6 -s --max-time 5 ipinfo.io/ip"; GeoUrl="https://ipinfo.io/json"; IspProperty="org"; CityProperty="city" },
@{ Name="ifconfig.co"; Cmd4="curl -4 -s --max-time 5 ifconfig.co"; Cmd6="curl -6 -s --max-time 5 ifconfig.co"; GeoUrl="https://ifconfig.co/json"; IspProperty="asn.name"; CityProperty="city" },
@{ Name="wtfismyip.com"; Cmd4="curl -4 -s --max-time 5 wtfismyip.com/text"; Cmd6="curl -6 -s --max-time 5 wtfismyip.com/text"; GeoUrl="https://wtfismyip.com/json"; IspProperty="YourFuckingISP"; CityProperty="YourFuckingCity" },
@{ Name="api.ipify.org"; Cmd4="curl -4 -s --max-time 5 api.ipify.org"; Cmd6="curl -6 -s --max-time 5 api6.ipify.org"; GeoUrl="https://geo.ipify.org/api/v2/country,city?apiKey=at_EAka35Dw9ocADDNNBC8iQbQlclYQk&ipAddress={IP_ADDRESS}"; IspProperty="isp"; CityProperty="location.city" },
@{ Name="ipwhois.app"; Cmd4="(curl -4 -s --max-time 5 https://ipwhois.app/json/ | ConvertFrom-Json).ip"; Cmd6="(curl -6 -s --max-time 5 https://ipwhois.app/json/ | ConvertFrom-Json).ip"; GeoUrl="https://ipwhois.app/json/"; IspProperty="isp"; CityProperty="city" },
@{ Name="ip.sb"; Cmd4="(curl -4 -s --max-time 5 https://api.ip.sb/geoip | ConvertFrom-Json).ip"; Cmd6="(curl -6 -s --max-time 5 https://api.ip.sb/geoip | ConvertFrom-Json).ip"; GeoUrl="https://api.ip.sb/geoip"; IspProperty="isp"; CityProperty="city" },
@{ Name="ident.me"; Cmd4="(curl -4 -s --max-time 5 https://ident.me/json | ConvertFrom-Json).ip"; Cmd6="(curl -6 -s --max-time 5 https://ident.me/json | ConvertFrom-Json).ip"; GeoUrl="https://ident.me/json" }, # Endpoint ini tidak menyediakan data GeoIP tambahan
# Layanan BARU yang ditambahkan: ip2location.io
@{ Name="ip2location.io"; Cmd4="(curl -4 -s --max-time 5 https://api.ip2location.io/ | ConvertFrom-Json).ip"; Cmd6="(curl -6 -s --max-time 5 https://api.ip2location.io/ | ConvertFrom-Json).ip"; GeoUrl="https://api.ip2location.io/"; IspProperty="as"; CityProperty="city_name" },
# Layanan yang hanya mengembalikan IP (plain text), sehingga GeoIP akan N/A
@{ Name="icanhazip.com"; Cmd4="curl -4 -s --max-time 5 icanhazip.com"; Cmd6="curl -6 -s --max-time 5 icanhazip.com" },
@{ Name="ifconfig.me"; Cmd4="curl -4 -s --max-time 5 ifconfig.me"; Cmd6="curl -6 -s --max-time 5 ifconfig.me" },
@{ Name="checkip.amazonaws.com"; Cmd4="curl -4 -s --max-time 5 checkip.amazonaws.com"; Cmd6="curl -6 -s --max-time 5 checkip.amazonaws.com" }
)
# 2. Regex untuk validasi alamat IP
$regexIPv4 = '^\b(?:\d{1,3}\.){3}\d{1,3}\b$'
$regexIPv6 = '^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$'
# 3. Proses Utama
Write-Host "🔍 Mengambil alamat IP & GeoIP dari berbagai layanan (paralel)..." -ForegroundColor Yellow
$results = $services | ForEach-Object -Parallel {
$ErrorActionPreference = 'SilentlyContinue'
# Impor regex dari scope utama
$regexIPv4 = $using:regexIPv4
$regexIPv6 = $using:regexIPv6
# Inisialisasi variabel
$ipv4 = "N/A"
$ipv6 = "N/A"
$isp = "N/A"
$city = "N/A"
# --- Ambil Alamat IP ---
try {
$output4 = (Invoke-Expression $_.Cmd4).Trim()
if ($output4 -match $regexIPv4) { $ipv4 = $Matches[0] }
} catch {}
try {
$output6 = (Invoke-Expression $_.Cmd6).Trim()
if ($output6 -match $regexIPv6) { $ipv6 = $Matches[0] }
} catch {}
# --- Ambil GeoIP jika layanan mendukung ---
if ($_.GeoUrl) {
try {
$urlToQuery = $_.GeoUrl
# Penanganan khusus untuk ipify yang memerlukan IP di URL-nya
if ($_.Name -eq "api.ipify.org") {
if ($ipv4 -ne "N/A") {
$urlToQuery = $_.GeoUrl -replace '{IP_ADDRESS}', $ipv4
} else {
# Lewati jika tidak ada IPv4 untuk dicari, karena API ini memerlukannya
throw "Tidak ada IPv4 untuk kueri GeoIP ipify"
}
}
# Khusus untuk IP2Location.io, tambahkan parameter API Key (jika diperlukan)
# Catatan: Jika Anda memiliki API key, ganti 'YOUR_API_KEY'
if ($_.Name -eq "ip2location.io") {
# Contoh: Jika API key diperlukan, uncomment baris di bawah ini dan ganti YOUR_API_KEY
# $urlToQuery = $urlToQuery + "?key=YOUR_API_KEY"
}
$geoResponse = Invoke-RestMethod -Uri $urlToQuery -TimeoutSec 5 -UseBasicParsing
# Mengambil properti ISP (bisa bersarang, contoh: 'asn.name')
if ($_.IspProperty -and $_.IspProperty.Contains('.')) {
$props = $_.IspProperty.Split('.')
$isp = $geoResponse.($props[0]).($props[1]) ?? "N/A"
} elseif ($_.IspProperty) {
$isp = $geoResponse.($_.IspProperty) ?? "N/A"
}
# Mengambil properti City (bisa bersarang, contoh: 'location.city')
if ($_.CityProperty -and $_.CityProperty.Contains('.')) {
$props = $_.CityProperty.Split('.')
$city = $geoResponse.($props[0]).($props[1]) ?? "N/A"
} elseif ($_.CityProperty) {
$city = $geoResponse.($_.CityProperty) ?? "N/A"
}
} catch {
# Biarkan ISP dan City tetap "N/A" jika terjadi error
}
}
# --- Kembalikan hasil sebagai satu objek ---
[PSCustomObject]@{
Service = $_.Name
IPv4 = $ipv4
IPv6 = $ipv6
ISP = $isp.Trim()
City = $city.Trim()
}
} -ThrottleLimit 10
# 4. Tampilkan hasil akhir
$results | Sort-Object Service | Format-Table -AutoSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment