Skip to content

Instantly share code, notes, and snippets.

@dweeber
Created October 26, 2012 22:54
Show Gist options
  • Save dweeber/3962033 to your computer and use it in GitHub Desktop.
Save dweeber/3962033 to your computer and use it in GitHub Desktop.
Phone Home Script
<?php
######################################################################
# Phonehome script to obtain IP of home router
#
# Call with wget from your internal machine
# with the command:
# wget -t 10 http://yourwebsite/phonehome.php?c=1234&cmd=1 -O /dev/null
#
######################################################################
$SY = array();
$SY['CODE'] = " 1234"; // Change to be your code
$SY['IPADDR'] = $_SERVER['REMOTE_ADDR'];
$SY['PCODE'] = 0; // Code found
$SY['PCMD'] = 0; // Cmd Found 0 = read 1 = (write)
$SY['FILE'] = 'phonehome.dat';
######################################################################
// Get the code if passed
if ( isset($_GET['c']) ) {
$SY['PCODE'] = intval ($_GET['c']);
}
if ( isset($_GET['cmd']) ) {
$SY['PCMD'] = intval($_GET['cmd']);
}
// Compare code we got with what it should be
if ($SY['PCODE'] == $SY['CODE'] ) {
// If cmd = 0 write address we found
if ($SY['PCMD'] == 0 ) {
$readval = file($SY['FILE']);
echo 'Recorded IP is: ' . $readval[0] . '<br/>';
} else {
$FP = fopen($SY['FILE'], "w");
if ($FP) {
fwrite($FP,$SY['IPADDR']);
fclose($FP);
}
echo 'Got it!<br/>';
}
} else {
echo 'ERROR, Wrong Access Codes<br/>';
}
######################################################################
# END OF MODULE
######################################################################
@dweeber
Copy link
Author

dweeber commented Oct 26, 2012

Initial version.

@dweeber
Copy link
Author

dweeber commented Oct 26, 2012

Corrected wget command with cmd=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment