Last active
April 19, 2020 09:00
-
-
Save rezkam/14096acd0360c8ecbff54b1353aeb956 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
"bytes" | |
"fmt" | |
"net" | |
"strings" | |
) | |
func main() { | |
fmt.Println(verifyBot("157.55.39.84", "msn.com.")) // true | |
fmt.Println(verifyBot("91.99.75.10", "google.com.")) // false | |
fmt.Println(verifyBot("66.249.66.1", "googlebot.com.")) // true | |
fmt.Println(verifyBot("66.249.64.118", "googlebot.com.")) // true | |
fmt.Println(verifyBot("66.249.64.116", "googlebot.com.")) // true | |
fmt.Println(verifyBot("66.249.92.71", "google.com.")) // true | |
fmt.Println(verifyBot("66.249.64.118", "googlebot.com.")) // true | |
fmt.Println(verifyBot("66.249.64.116", "googlebot.com.")) // true | |
fmt.Println(verifyBot("66.249.83.221", "google.com.")) // true | |
fmt.Println(verifyBot("66.249.93.223", "google.com.")) // true | |
fmt.Println(verifyBot("66.249.81.116", "google.com.")) // true | |
fmt.Println(verifyBot("66.249.92.75", "google.com.")) // true | |
fmt.Println(verifyBot("157.55.39.25", "msn.com.")) // true | |
fmt.Println(verifyBot("13.66.139.1", "msn.com.")) // true | |
fmt.Println(verifyBot("207.46.13.179", "msn.com.")) // true | |
fmt.Println(verifyBot("66.249.89.180", "google.com.")) // true | |
} | |
// verifyBot used verify IP address with a reverse and forward DNS lookup | |
func verifyBot(ip string, identifier string) bool { | |
// reverse dns lookup | |
rev, err := net.LookupAddr(ip) | |
if err != nil { | |
panic(err) | |
} | |
if strings.HasSuffix(rev[0], identifier) { | |
// forward dns lookup | |
frw, err := net.LookupIP(rev[0]) | |
if err != nil { | |
panic(err) | |
} | |
// check forward dns result with the original bot address | |
parsedIP := net.ParseIP(ip) | |
for _, res := range frw { | |
if bytes.Compare(res, parsedIP) == 0 { | |
return true | |
} | |
} | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment