Jump to content

Archived

This topic is now archived and is closed to further replies.

rab

C to Module?

Recommended Posts

Alright I have a certin peice of C code that is hard to port. I was wondering if there was a safe way of executing it and rettrieving information from it or compiling it as a php module. Is there any way to do this?

Share this post


Link to post
Share on other sites
Have a look at

[a href=\"http://us3.php.net/exec\" target=\"_blank\"]http://us3.php.net/exec[/a]

Share this post


Link to post
Share on other sites
The out put of the program is
[code]
69.164.100.200   5150
    83.71.83.19   56129
   24.14.144.22   1401
   70.125.156.6   5150
  24.33.131.239   5150
206.174.154.174   5150
  70.20.233.160   50206
   24.55.91.108   5150
   24.86.86.200   62841
  24.15.190.153   5150
  70.50.128.152   63630
     72.81.9.43   5150
   65.2.139.121   50108
   12.219.67.24   32929
  68.11.123.247   60542
81.164.109.163   5150
69.192.166.103   63553
   4.225.34.193   5150
   68.47.43.164   5150
  71.234.75.198   62015
65.175.251.198   5150
24.131.247.197   5150
  172.149.37.31   5150
  68.197.169.86   5150
  66.245.63.108   12417
[/code]

I need to parse through that for a specific IP how would I do this.

Note I tried exec, system, passthru and non of them return this.

Share this post


Link to post
Share on other sites
[!--quoteo(post=373634:date=May 13 2006, 09:07 PM:name=rab)--][div class=\'quotetop\']QUOTE(rab @ May 13 2006, 09:07 PM) [snapback]373634[/snapback][/div][div class=\'quotemain\'][!--quotec--]
The out put of the program is
[code]
69.164.100.200   5150
    83.71.83.19   56129
   24.14.144.22   1401
   70.125.156.6   5150
  24.33.131.239   5150
206.174.154.174   5150
  70.20.233.160   50206
   24.55.91.108   5150
   24.86.86.200   62841
  24.15.190.153   5150
  70.50.128.152   63630
     72.81.9.43   5150
   65.2.139.121   50108
   12.219.67.24   32929
  68.11.123.247   60542
81.164.109.163   5150
69.192.166.103   63553
   4.225.34.193   5150
   68.47.43.164   5150
  71.234.75.198   62015
65.175.251.198   5150
24.131.247.197   5150
  172.149.37.31   5150
  68.197.169.86   5150
  66.245.63.108   12417
[/code]

I need to parse through that for a specific IP how would I do this.

Note I tried exec, system, passthru and non of them return this.
[/quote]

Try this Rab,

[code]
<?php
$string = " 69.164.100.200   5150
    83.71.83.19   56129
   24.14.144.22   1401
   70.125.156.6   5150
  24.33.131.239   5150
206.174.154.174   5150
  70.20.233.160   50206
   24.55.91.108   5150
   24.86.86.200   62841
  24.15.190.153   5150
  70.50.128.152   63630
     72.81.9.43   5150
   65.2.139.121   50108
   12.219.67.24   32929
  68.11.123.247   60542
81.164.109.163   5150
69.192.166.103   63553
   4.225.34.193   5150
   68.47.43.164   5150
  71.234.75.198   62015
65.175.251.198   5150
24.131.247.197   5150
  172.149.37.31   5150
  68.197.169.86   5150
  66.245.63.108   12417";
  
/* The IP we want to find */
$IPSearch = "68.47.43.164";

/* Break the string into an array, each line is a new element */
$IPListArr = explode("\n", $string);
/* Loop through the array */
for($i=0; $i <= count($IPListArr); $i++){
    /* Trim whitespace */
    $Line = trim($IPListArr[$i]);
    /* Break up the IP and Port*/
    $IPVals = explode("   ", $Line);
    /* Is it the one we want to find? */
    if($IPVals[0] == $IPSearch){
        /* yes, echo it out */
        echo "IP Found: ". $Line;
    }
}
?>
[/code]

That is assuming you can get the output of the program into a string in php

Share this post


Link to post
Share on other sites
Finding it wont be a problem, getting the return into a string is.

Share this post


Link to post
Share on other sites
If you run your C program from the command prompt, does it returm the output to the screen?

In other words, does it write to the stdout stream?

Share this post


Link to post
Share on other sites
Yes it does

EDIT::::

popen gives me Resource id #2.

Now how should i get the IP's and Ports from it? or is there a better way to do this.

Share this post


Link to post
Share on other sites
try
[code]$command = 'dir *.php';
$arr = array();
$res = ex_ec($command, $arr);   // remove _ from ex_ec

  // check output in $arr
echo '<pre>', print_r($arr, true), '</pre>';[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=373733:date=May 14 2006, 08:45 AM:name=rab)--][div class=\'quotetop\']QUOTE(rab @ May 14 2006, 08:45 AM) [snapback]373733[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Finding it wont be a problem, getting the return into a string is.
[/quote]

To quote one of your earlier posts..

"I need to parse through that for a specific IP how would I do this."

*shrug*

Share this post


Link to post
Share on other sites
Now my question is, when i let users enter things, like IP's , how can i stop them from doing things they are supossed to. Example, if they enter "124.35.64.23; wget netcat; ./netcat", that will download netcat and execute it. How can i stop things like that.

Share this post


Link to post
Share on other sites
Use this and/or regular expression functions (ereg/preg):

[a href=\"http://us2.php.net/manual/en/function.escapeshellcmd.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.escapeshellcmd.php[/a]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.