Skip to content

Instantly share code, notes, and snippets.

@Jire
Created August 19, 2017 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jire/fb7d8aa0b873eb6d17eb57a4fe422cbe to your computer and use it in GitHub Desktop.
Save Jire/fb7d8aa0b873eb6d17eb57a4fe422cbe to your computer and use it in GitHub Desktop.
haHAA
val service: ExecutorService = Executors.newFixedThreadPool(512)
fun main(args: Array<String>) {
val jsonFile = File("aws.json")
val o = JsonParser().parse(FileReader(jsonFile)).asJsonObject
val arr = o.get("prefixes").asJsonArray
for (ipE in arr) {
val prefix = ipE["ip_prefix"].asString
val ipPrefix = prefix.split("/")[0].replace(".0.0", "")
for (i in 0..255) {
for (i2 in 0..255) {
val ip = "$ipPrefix.$i.$i2"
portIsOpen(service, ip, 5201, 250)
}
}
}
}
fun portIsOpen(es: ExecutorService, ip: String, port: Int, timeout: Int): Future<Boolean>
= es.submit(Callable {
try {
val socket = Socket()
socket.connect(InetSocketAddress(ip, port), timeout)
socket.close()
println("$ip:$port")
return@Callable true
} catch (ex: Exception) {
return@Callable false
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment