Created
September 29, 2015 02:11
-
-
Save shawnweisfeld/c5491567b09f24ff7e11 to your computer and use it in GitHub 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 | |
/** | |
* Plugin Name: Port Pinger | |
* Plugin URI: http://www.shawnweisfeld.com/ | |
* Description: the goal of this plugin is to test outbound connectivity to a given URI and port | |
* Version: 0.1 | |
* Author: Shawn Weisfeld | |
* Author URI: http://www.shawnweisfeld.com | |
* License: GPL12 | |
*/ | |
function ping($host, $port, $timeout) | |
{ | |
$tB = microtime(true); | |
$fP = fSockOpen($host, $port, $errno, $errstr, $timeout); | |
if (!$fP) { return "I could not connect to ".$host.":".$port; } | |
$tA = microtime(true); | |
return "I connected to ".$host.":".$port." in ".round((($tA - $tB) * 1000), 0)." ms"; | |
} | |
function PingPort( $atts ) { | |
$output = ''; | |
$pull_quote_atts = shortcode_atts( array( | |
'host' => 'www.googole.com', | |
'port' => '80', | |
'timeout' => '10', | |
), $atts ); | |
$output .= '<p>'; | |
$output .= ping($pull_quote_atts[ 'host' ] , $pull_quote_atts[ 'port' ] , $pull_quote_atts[ 'timeout' ] ); | |
$output .= '</p>'; | |
return $output; | |
} | |
add_shortcode( 'PingPort', 'PingPort' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment