Last active
November 29, 2019 23:12
-
-
Save sarahg/f778807090ce4098f67d9f0cab7c2a46 to your computer and use it in GitHub Desktop.
This is a Golang script to generate a MySQL query that you can use to block an IP range in Drupal 8. Run it like this: go run blockrange.go 123.456.789 (in a situation where you need to block 123.456.789.*). For Drupal 7, change the table name in row 12 to blocked_ips.
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" | |
"strconv" | |
"os" | |
) | |
func main() { | |
baseIP := "('" + os.Args[1] + "." | |
queryStart := "INSERT INTO ban_ip (ip) VALUES" | |
var ipList string | |
for n := 0; n <= 255; n++ { | |
ipList = ipList + baseIP + strconv.Itoa(n) + "')" | |
if n == 255 { | |
continue; | |
} | |
ipList = ipList + ", " | |
} | |
queryEnd := ";" | |
fmt.Println(queryStart + ipList + queryEnd) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would be nice to make this interactive (prompt for the baseIP)