Created
February 6, 2015 19:15
-
-
Save stypr/cb4fe114632bf5767844 to your computer and use it in GitHub Desktop.
cloudflare auto ddns + memory flush
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
#!/usr/bin/php | |
<?php | |
/* | |
* crontab -e | |
* 0 5 * * * ~/ping.php | |
*/ | |
error_reporting(0); | |
set_time_limit(0); | |
$domain = "stypr.com"; | |
$subdomain = "home"; | |
$zone_id = "you need to get this from cloudflare"; | |
$email = "[email protected]"; | |
$token = "you need to get this from cloudflare"; | |
header("Content-Type: text/html; charset=utf-8"); | |
@system("/sbin/sysctl vm.drop_caches=3"); | |
function getfirstIP(){ | |
$fp = @fsockopen("ip4.me", "80", $errno, $errstr, 3); | |
if(!$fp) die("Killed"); | |
$packet = "GET / HTTP/1.0\r\n"; | |
$packet .= "Host: ip4.me\r\n"; | |
$packet .= "User-Agent: Mozilla/5.0\r\n\r\n"; | |
@fwrite($fp, $packet); | |
while($buffer = fgets($fp, 2048)){ | |
$test .= fgets($fp, 2048); | |
} | |
fclose($fp); | |
$test = explode("+3>",$test); | |
$test = explode("</font", $test[1]); | |
return $test[0]; | |
} | |
function getsecondIP(){ | |
$fp = @fsockopen("ipip.kr", "80", $errno, $errstr, 3); | |
if(!$fp) die("Killed"); | |
$packet = "GET / HTTP/1.0\r\n"; | |
$packet .= "Host: ipip.kr\r\n"; | |
$packet .= "User-Agent: Mozilla/5.0\r\n\r\n"; | |
@fwrite($fp, $packet); | |
while($buffer = fgets($fp, 2048)){ | |
$test .= fgets($fp, 2048); | |
} | |
fclose($fp); | |
$test = explode("Your IP is ",$test); | |
$test = explode("</title>", $test[1]); | |
return $test[0]; | |
} | |
function getreceiver(){ | |
$fp = @fsockopen("stypr.com", "80", $errno, $errstr, 3); | |
if(!$fp) die("Killed"); | |
$packet = "GET /receiver.php?mode=receiver HTTP/1.0\r\n"; | |
$packet .= "Host: stypr.com\r\n"; | |
$packet .= "User-Agent: Mozilla/5.0\r\n\r\n"; | |
@fwrite($fp, $packet); | |
$test = fgets($fp, 128); | |
fclose($fp); | |
die("Success"); | |
} | |
$first = getfirstIP(); | |
$second= getsecondIP(); | |
if($first == $second){ | |
@system("curl -s \"https://www.cloudflare.com/api_json.html?a=rec_edit&z=".$domain."&id=".$zone_id."&content=".$first."&ttl=1&name=".$subdomain."&type=A&email=".$email."&tkn=".$token."\""); | |
}else{ | |
getreceiver(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment