DtDNS: PHP cURL 1: Difference between revisions

m
Reverted edits by Upazixorys (Talk); changed back to last version by Ric
No edit summary
m (Reverted edits by Upazixorys (Talk); changed back to last version by Ric)
 
Line 1: Line 1:
=[http://egyworene.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]=
{{Nav DtDNS}}
{{Nav DtDNS}}
'''''Introduction'''''
'''''Introduction'''''
Line 13: Line 12:


Extracting the IP address is performed using a regex since we are specifically targeting information we want and discarding any other page content means any harmful code will never be run.
Extracting the IP address is performed using a regex since we are specifically targeting information we want and discarding any other page content means any harmful code will never be run.
{|cellspacing="6"
{|cellspacing="6"
|-
|-
|
|
<pre>
<pre>
&lt;?php
<?php
$ch=curl_init();
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,'http://myip.dtdns.com');
curl_setopt($ch,CURLOPT_URL,'http://myip.dtdns.com');
Line 31: Line 30:
else{
else{
   // Extract IP address  
   // Extract IP address  
  if(preg_match(&quot;/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/&quot;, $buffer, $ipmatch)){   
  if(preg_match("/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/", $buffer, $ipmatch)){   
     $ip = $ipmatch[0]; // Save IP to variable
     $ip = $ipmatch[0]; // Save IP to variable
  }
  }
}
}
     print $ip;  // Test code  
     print $ip;  // Test code  
?&gt;
?>
&lt;/pre&gt;
</pre>
|
|
* Initialize Curl and save memory location in variable $ch
* Initialize Curl and save memory location in variable $ch
Line 59: Line 58:
|-
|-
|
|
&lt;pre&gt;
<pre>
&lt;?php
<?php
$ch=curl_init();
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,'http://myip.dtdns.com');
curl_setopt($ch,CURLOPT_URL,'http://myip.dtdns.com');
Line 74: Line 73:
else{
else{
   // Extract IP address  
   // Extract IP address  
  if(preg_match(&quot;/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/&quot;, $buffer, $ipmatch)){   
  if(preg_match("/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/", $buffer, $ipmatch)){   
     $ip = $ipmatch[0]; // Save IP to variable
     $ip = $ipmatch[0]; // Save IP to variable
  }
  }
}
}
     print $ip;  // Test code  
     print $ip;  // Test code  
?&gt;
?>
&lt;/pre&gt;
</pre>
|
|
'''''Run Test 1'':'''
'''''Run Test 1'':'''
* Run servers
* Run servers
* Type '''&lt;nowiki&gt;http:&lt;/nowiki&gt;//localhost/dtdns_test_1.php''' into your browser
* Type '''<nowiki>http:</nowiki>//localhost/dtdns_test_1.php''' into your browser
* Result: Returns your '''current'''IP address for example  
* Result: Returns your '''current'''IP address for example  
&lt;pre&gt;
<pre>
179.79.934.216
179.79.934.216
&lt;/pre&gt;
</pre>
|}
|}
'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
Line 100: Line 99:
|-
|-
|
|
&lt;pre&gt;
<pre>
COLOR B0
COLOR B0
@echo off
@echo off
Line 114: Line 113:
popd
popd
EXIT
EXIT
&lt;/pre&gt;
</pre>
|
|
'''''Run Test 2'':'''
'''''Run Test 2'':'''
Line 120: Line 119:
* Double click on Run_dtdns_test_1.bat
* Double click on Run_dtdns_test_1.bat
* Result: Returns your '''current''' IP address for example  
* Result: Returns your '''current''' IP address for example  
&lt;pre&gt;
<pre>
179.79.934.216Press any key to continue . . .
179.79.934.216Press any key to continue . . .
&lt;/pre&gt;
</pre>
|}
|}
'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''