Jump to content

php port opening help


shankcode

Recommended Posts

Hello experts !!!

I have written a php code to make a telnet connection and it works well. But there is only one problem. If I call this php from html page, it requires to enter IP, user name and password every time. I'm expecting to make this program like this. User inputs IP, User Name and Password to HTML form and then it submits to the php and makes the telnet connection. Then the user types the telnet command ( it depends on the device ) to the html text box and pass it to php. Then php will retrieve the out put by passing the command to the remote device. My following code do only half of my expects. I have used "help" command to test.

 

 

<?php

 

if($_POST['action']== 'connect'){

 

$ip = $_POST['ip'];

$user = $_POST['user'];

$pass = $_POST['pass'];

$fp=fsockopen($ip,23);

 

fputs($fp,"$user\r");

sleep(2);

fputs($fp,"$pass\r");

sleep (2);

$sys = fread($fp,8190);

$result = $sys;

fputs($fp,"help\r");

sleep (4);

$sys = fread($fp,8190);

fclose($fp);

$r=array($result,"$",">","#");

$result = str_replace($r,"",$sys);

 

echo ("$result");

exit;

}

?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/239517-php-port-opening-help/
Share on other sites

My following code do only half of my expects.

 

You never told us what half it did and what half it didn't do. I am guessing that you do not want to enter your ip, user name, and password every time you want to send a command. The trouble with that is PHP does not remember variables between programs.

 

You might want to look into ajax to do this. Your ip, user name, and password can be set by javascript and you just enter the commands and view results.

 

Use sessions to remember ip, username and password.

 

session_start();

$ip = (isset($_SESSION['ip'])) ? $_SESSION['ip'] : $_POST['ip'];
$user = (isset($_SESSION['user'])) ? $_SESSION['user'] : $_POST['user'];
$pass = (isset($_SESSION['pass'])) ? $_SESSION['pass'] : $_POST['pass'];

Archived

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

×
×
  • Create New...

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.