Tuesday, April 12, 2011

php - keyboard input

I was thinking yesterday that is it possible in PHP to take input from keyboard. I started to digg and find out it is possible but no one use it because PHP was not designed to take input from keyboard :) anyway i am posting code here take a look :

#!/usr/bin/php
[php open tag]
function getinput(){
print("Your input: ");
$stdin = fopen("php://stdin", 'r');
$input = fgets($stdin, 1024);
$input = trim($input);
fclose($stdin);
return $input;
}

function output($message){
print $message."\n";
}

$message = getinput();
output($message);
[php end tag]

list open ports and unix sockets

To do this I use netstat command to list all open ports: $ sudo netstat -tuplen to list open ports and unix sockets: $ sudo netstat -...