Created
August 31, 2016 11:52
-
-
Save iamso/050845c199590f6e2443e564610e5b0f to your computer and use it in GitHub Desktop.
Output hosts file entries for use in VirtualBox and Parallels Desktop
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
<?php | |
$file = file_get_contents("/etc/hosts"); | |
$lines = explode("\n", $file); | |
$hosts = array(); | |
foreach($lines as $line) { | |
if (preg_match("/^#/", $line) || !$line) { | |
continue; | |
} | |
$line = preg_replace("/((\d+\.+\d+\.*)+)\s*/", '', $line); | |
$line = preg_replace("/\:\:\d\s*/", '', $line); | |
$line = preg_replace("/\s*\#\s*.*/", '', $line); | |
$line = preg_replace("/\t*/", '', $line); | |
$hosts[] = $line; | |
} | |
$hosts = array_unique($hosts); | |
sort($hosts); | |
header('Content-Type: text/plain'); | |
echo "VirtualBox:\n-----------\n"; | |
foreach($hosts as $host) { | |
echo "10.0.2.2 $host\n"; | |
} | |
echo "\n\nParallels Desktop:\n------------------\n"; | |
foreach($hosts as $host) { | |
echo "10.211.55.2 $host\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment