Created
August 19, 2017 00:19
-
-
Save Jire/fb7d8aa0b873eb6d17eb57a4fe422cbe to your computer and use it in GitHub Desktop.
haHAA
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
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