Index: wp-includes/comment.php
===================================================================
--- wp-includes/comment.php	(revision 21261)
+++ wp-includes/comment.php	(working copy)
@@ -1670,7 +1670,6 @@
  */
 function do_all_pings() {
 	global $wpdb;
-
 	// Do pingbacks
 	while ($ping = $wpdb->get_row("SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
 		delete_metadata_by_mid( 'post', $ping->meta_id );
@@ -1776,17 +1775,11 @@
 
 	$pung = get_pung($post_ID);
 
-	// Variables
-	$ltrs = '\w';
-	$gunk = '/#~:.?+=&%@!\-';
-	$punc = '.:?\-';
-	$any = $ltrs . $gunk . $punc;
-
 	// Step 1
 	// Parsing the post, external links (if any) are stored in the $post_links array
 	// This regexp comes straight from phpfreaks.com
 	// http://www.phpfreaks.com/quickcode/Extract_All_URLs_on_a_Page/15.php
-	preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp);
+	$post_links_temp = parse_content_for_ping_urls( $content );
 
 	// Step 2.
 	// Walking thru the links array
@@ -1797,18 +1790,15 @@
 	// http://dummy-weblog.org/post.php
 	// We don't wanna ping first and second types, even if they have a valid <link/>
 
-	foreach ( (array) $post_links_temp[0] as $link_test ) :
-		if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post_ID) // If we haven't pung it already and it isn't a link to itself
-				&& !is_local_attachment($link_test) ) : // Also, let's never ping local attachments.
-			if ( $test = @parse_url($link_test) ) {
-				if ( isset($test['query']) )
-					$post_links[] = $link_test;
-				elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) )
-					$post_links[] = $link_test;
-			}
-		endif;
-	endforeach;
-
+	foreach ( (array) $post_links_temp[0] as $link_test ) 
+		if ( !in_array( $link_test, $pung ) 
+			&& ( url_to_postid( $link_test ) != $post_ID ) // If we haven't pung it already and it isn't a link to itself
+			&& !is_local_attachment( $link_test )  // Also, let's never ping local attachments.
+			&& check_ping_url( $link_test ) ) {
+			
+			$post_links[] = $link_test;
+		}	
+		
 	do_action_ref_array( 'pre_ping', array( &$post_links, &$pung, $post_ID ) );
 
 	foreach ( (array) $post_links as $pagelinkedto ) {
Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 21261)
+++ wp-includes/functions.php	(working copy)
@@ -393,6 +393,44 @@
 }
 
 /**
+ * Matches pingable URLs in content
+ *
+ * @since 3.5.0
+ *
+ * @param string $content Post content.
+ * @return array of URLs found in content
+ */
+function parse_content_for_ping_urls( $content ) {
+	$ltrs = '\w';
+	$gunk = '/#~:.?+=&%@!\-';
+	$punc = '.:?\-';
+	$any = $ltrs . $gunk . $punc;
+	
+	preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp );
+	return $post_links_temp;
+}
+
+/**
+ * Checks ping URLs
+ *
+ * @since 3.5.0
+ *
+ * @param string $url URL.
+ * @return bool|string False on failure and url if it passes tests.
+ */
+function check_ping_url( $url ) {
+	$siteurl = @parse_url( get_option( 'siteurl' ) );
+	$test = @parse_url( $url );
+	if ( $test && strstr( $test['host'], '.' ) && $test['host'] != $siteurl['host'] ) { // don't ping URLs (.-less vhosts) on localhost, HEAD requests will cause massive seg faults
+		if ( isset( $test['query'] ) )
+			return $url;
+		elseif ( isset( $test['path'] ) && ( $test['path'] != '/' ) && ( $test['path'] != '' ) )
+			return $url;
+	}
+	return false;
+}
+
+/**
  * Check content for video and audio links to add as enclosures.
  *
  * Will not add enclosures that have already been added and will
@@ -416,14 +454,8 @@
 	$post_links = array();
 
 	$pung = get_enclosed( $post_ID );
+	$post_links_temp = parse_content_for_ping_urls( $content );
 
-	$ltrs = '\w';
-	$gunk = '/#~:.?+=&%@!\-';
-	$punc = '.:?\-';
-	$any = $ltrs . $gunk . $punc;
-
-	preg_match_all( "{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp );
-
 	foreach ( $pung as $link_test ) {
 		if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
 			$mids = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $link_test ) . '%') );
@@ -432,18 +464,10 @@
 		}
 	}
 
-	foreach ( (array) $post_links_temp[0] as $link_test ) {
-		if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
-			$test = @parse_url( $link_test );
-			if ( false === $test )
-				continue;
-			if ( isset( $test['query'] ) )
-				$post_links[] = $link_test;
-			elseif ( isset($test['path']) && ( $test['path'] != '/' ) &&  ($test['path'] != '' ) )
-				$post_links[] = $link_test;
-		}
-	}
-
+	foreach ( (array) $post_links_temp[0] as $link_test )
+		if ( !in_array( $link_test, $pung ) && check_ping_url( $link_test ) ) // If we haven't pung it already
+			$post_links[] = $link_test;
+		
 	foreach ( (array) $post_links as $url ) {
 		if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape( $url ) . '%' ) ) ) {
 
