rab Posted May 13, 2006 Share Posted May 13, 2006 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? Quote Link to comment Share on other sites More sharing options...
Barand Posted May 13, 2006 Share Posted May 13, 2006 Have a look at [a href=\"http://us3.php.net/exec\" target=\"_blank\"]http://us3.php.net/exec[/a] Quote Link to comment Share on other sites More sharing options...
rab Posted May 14, 2006 Author Share Posted May 14, 2006 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 5150206.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 Link to comment Share on other sites More sharing options...
Prismatic Posted May 14, 2006 Share Posted May 14, 2006 [!--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 5150206.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 5150206.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 6054281.164.109.163 515069.192.166.103 63553 4.225.34.193 5150 68.47.43.164 5150 71.234.75.198 6201565.175.251.198 515024.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 Quote Link to comment Share on other sites More sharing options...
rab Posted May 14, 2006 Author Share Posted May 14, 2006 Finding it wont be a problem, getting the return into a string is. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 14, 2006 Share Posted May 14, 2006 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? Quote Link to comment Share on other sites More sharing options...
rab Posted May 14, 2006 Author Share Posted May 14, 2006 Yes it doesEDIT::::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. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 14, 2006 Share Posted May 14, 2006 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] Quote Link to comment Share on other sites More sharing options...
Prismatic Posted May 14, 2006 Share Posted May 14, 2006 [!--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* Quote Link to comment Share on other sites More sharing options...
rab Posted May 14, 2006 Author Share Posted May 14, 2006 worded bad, sorry. :/ Quote Link to comment Share on other sites More sharing options...
rab Posted May 15, 2006 Author Share Posted May 15, 2006 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. Quote Link to comment Share on other sites More sharing options...
toplay Posted May 15, 2006 Share Posted May 15, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.