Random hostname generator (*nix) 07-03-2013, 10:13 PM
#1
I was getting tired of having the same IP on my schools network.
It didn't help just to spoof my mac.
So I wrote a this script. I just run the script on boot.
It's a simple script, but I thought someone could maybe use it.
It didn't help just to spoof my mac.
So I wrote a this script. I just run the script on boot.
It's a simple script, but I thought someone could maybe use it.
PHP Code:
#!/usr/bin/php
<?php
/********************************************
* Random host generator *
* * * * * * * * * * * * *
* The script takes 3 arguments
* arg 1: Path to hosts file
* arg 2: Path to hostname file
* arg 3: Path to list of hostnames
*
* The script could easily be
* modified to have the paths hardcoded
* in the script, so you didn't had to pass
* any arguments
* Just replace all $argv[*] with your paths
*********************************************/
$etc_hosts = file($argv[1]);
$hostname = file($argv[3]);
$h = array_rand($hostname,1);
$hostname = $hostname[$h];
file_put_contents($argv[2], $hostname);
$replacement = array(1 => "127.0.1.1 $hostname");
$etc_hosts = array_replace($etc_hosts,$replacement);
file_put_contents($argv[1], $etc_hosts);
$hostname = str_replace("\n","",$hostname);
$setHost = "hostname ".$hostname;
system($setHost);
?>
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)