Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save artulloss/5e40b251e4e0501527edddf3644e5762 to your computer and use it in GitHub Desktop.
Save artulloss/5e40b251e4e0501527edddf3644e5762 to your computer and use it in GitHub Desktop.
<?php
const PATTERN = '~" translate="no">(.+)<\/a><\/div>~';
$time = time();
$today = strtotime(date('Y-m-d', $time));
$dateTime = (new DateTime())->setTimestamp($time - $today);
$timeString = 'T' . $dateTime->format("His") . 'Z';
$hourStuff = $timeString;
$timesToRun = intval(prompt("How many times do you want to run the script?"));
if($timesToRun === 0)
return;
prompt('Generating names, this may take a while...', false);
$context = stream_context_create([ // Spoofs user agent
'http' => [
// 'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36',
'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
],
'ssl' => [
"verify_peer"=>false,
"verify_peer_name"=>false,
]
]);
$now = new DateTime();
$names = [];
for($i = 0; $i < $timesToRun; $i++) {
$now->add(new DateInterval('P1D')); // Adds a day
$timeString = $now->format('Ymd');
$result = file_get_contents('https://namemc.com/minecraft-names?time=' . $timeString . $hourStuff, false, $context);
preg_match_all(PATTERN, $result, $scraped);
$scraped = (array)$scraped[1];
$names = array_unique(array_merge($names, $scraped));
}
$time = time() - $time;
echo 'Generated ' . count($names) . " unique names in $time seconds" . PHP_EOL;
/* Uncomment this if you want to generate IP addresses :P
foreach ($names as $key => $name) {
unset($names[$key]);
$names[strtr($name, ['_' => ''])] = long2ip(mt_rand(0, 4294967295));
}
*/
echo json_encode($names, JSON_PRETTY_PRINT);
function prompt(string $prompt, $getInput = true): ?string{
echo $prompt . PHP_EOL;
if($getInput) {
$line = fgets(STDIN);
return trim($line);
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment