Jump to content


Photo

C to Module?


  • Please log in to reply
11 replies to this topic

#1 rab

rab
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts

Posted 13 May 2006 - 12:59 PM

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?

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 13 May 2006 - 07:25 PM

Have a look at

[a href=\"http://us3.php.net/exec\" target=\"_blank\"]http://us3.php.net/exec[/a]
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 rab

rab
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts

Posted 14 May 2006 - 02:07 AM

The out put of the program is
 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

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.

#4 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 14 May 2006 - 07:21 AM

[!--quoteo(post=373634:date=May 13 2006, 09:07 PM:name=rab)--][div class=\'quotetop\']QUOTE(rab @ May 13 2006, 09:07 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
The out put of the program is
 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

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,

<?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;
    }
}
?>

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

#5 rab

rab
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts

Posted 14 May 2006 - 01:45 PM

Finding it wont be a problem, getting the return into a string is.

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 14 May 2006 - 01:57 PM

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?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#7 rab

rab
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts

Posted 14 May 2006 - 02:24 PM

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.

#8 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 14 May 2006 - 05:34 PM

try
$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>';

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#9 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 14 May 2006 - 08:48 PM

[!--quoteo(post=373733:date=May 14 2006, 08:45 AM:name=rab)--][div class=\'quotetop\']QUOTE(rab @ May 14 2006, 08:45 AM) View Post[/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*

#10 rab

rab
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts

Posted 14 May 2006 - 11:27 PM

worded bad, sorry. :/

#11 rab

rab
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts

Posted 15 May 2006 - 01:53 AM

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.

#12 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 15 May 2006 - 02:23 AM

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]






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users