Last active
March 10, 2024 02:46
-
-
Save jniltinho/4764dad3c1c63a1292a3f10fb844011b to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"fmt" | |
"net" | |
"os" | |
"strings" | |
) | |
/* | |
## https://goplay.tools/snippet/37-MxfGC4Mp | |
## https://socketloop.com/tutorials/golang-reverse-ip-address-for-reverse-dns-lookup-example | |
Para Compilar voce precisa instalar Golang 1.20 | |
go build -ldflags="-s -w" check-rbl.go | |
Como usar | |
./check-rbl dnsbl.spfbl.net 104.219.19.88 | |
*/ | |
func ReverseIPAddress(ip net.IP) string { | |
if ip.To4() != nil { | |
// split into slice by dot . | |
addressSlice := strings.Split(ip.String(), ".") | |
reverseSlice := []string{} | |
for i := range addressSlice { | |
octet := addressSlice[len(addressSlice)-1-i] | |
reverseSlice = append(reverseSlice, octet) | |
} | |
return strings.Join(reverseSlice, ".") | |
} else { | |
println("Invalid IPv4 Address") | |
return "1.0.0.127" | |
} | |
} | |
func main() { | |
if len(os.Args) < 3 { | |
fmt.Printf("\nUsage:\n\t%s rbl ipaddress\n", os.Args[0]) | |
fmt.Printf("\t%s dnsbl.spfbl.net 74.63.210.183\n\n", os.Args[0]) | |
os.Exit(1) | |
} | |
if len(os.Args) > 2 { | |
ipAddress := net.ParseIP(os.Args[2]) | |
reverseIpAddress := ReverseIPAddress(ipAddress) | |
reverseIpAddress = fmt.Sprintf("%s.%s", reverseIpAddress, os.Args[1]) | |
//fmt.Println("Before:", ipAddress.To4()) | |
//fmt.Println("After:", reverseIpAddress) | |
//ip, err := net.LookupHost(reverseIpAddress) | |
ip, err := net.ResolveIPAddr("ip", reverseIpAddress) | |
if err != nil { | |
fmt.Print("unlisted:") | |
os.Exit(0) | |
} | |
fmt.Print("listed:", ip.String()) | |
os.Exit(1) | |
} | |
os.Exit(0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment