Page 1 of 1

php and telnet (again)

Posted: Wed Aug 22, 2007 10:51 am
by funguse
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello,
I'm currently building a intranet webpage in php for my employer and he has asked me to integrate a script that checks the status on one of our servers. 
the server is an IBM running AIX on the same network as the host server. 
I can view the status by loggin into the server as root and using hummingbird (software) or using telnet.

the command im using to see the status is: topas which displays (see image 1)

what i managed to do so far is use the script provided [url=http://www.geckotribe.com/php-telnet/]by Antone Roundy[/url] and connect to the server but not using the root username and password.

i know this doesnt tell a right lot so i'm gonna put some more screenshots on to tell you what i am doing when loggin onto the server using the root username and password.

on image 2 you input the root username and password, on images 3-5 you have to select through the option till you are able to input the topas command.

when using the script (modified it a bit) im trying to get past the first few return keys prompts but it is not letting me do it. and one know how i can get around this?

thanks

[b]Mark[/b]


[url=http://mddigital.co.uk/mark/topas.jpg]image 1[/url]
[url=http://mddigital.co.uk/mark/login1.JPG]image 2[/url]
[url=http://mddigital.co.uk/mark/login2.JPG]image 3[/url]
[url=http://mddigital.co.uk/mark/login3.JPG]image 4[/url]
[url=http://mddigital.co.uk/mark/login4.JPG]image 5[/url]

Code: Select all

<?php 

	require_once "PHPTelnet.php";
	
	$telnet = new PHPTelnet();
	$telnet->show_connect_error=0;
	
	// if the first argument to Connect is blank,
	// PHPTelnet will connect to the local host via 127.0.0.1
	$result = $telnet->Connect('server.ip,'username','password');
	
	switch ($result) {
		case 0: 
		
			echo "start telnet<br>";
			$telnet->DoCommand('\r\n', $result);
			ffile($result);
			$telnet->DoCommand('\r\n', $result);
			ffile($result);
			/*
			$telnet->DoCommand('', $result);
			ffile($result);*/
		
			// say Disconnect(0); to break the connection without explicitly logging out
			echo "end telnet<br>";
			ffile("\nEND\n");
				
			$telnet->Disconnect();
		break; 
		case 1:
			ffile( '[PHP Telnet] Connect failed: Unable to open network connection');
			break; 
		case 2:
			ffile( '[PHP Telnet] Connect failed: Unknown host');
			break; 
		case 3:
			ffile( '[PHP Telnet] Connect failed: Login failed');
			break; 
		case 4:
			ffile( '[PHP Telnet] Connect failed: Your PHP version does not support PHP Telnet');
			break; 
	}
	
	function ffile($result)
	{
		$File = "log.txt"; 
		//a = amend, w = write
		$Handle = fopen($File, 'a');
		$Data = $result; 
		fwrite($Handle, $Data); 
		echo $result;
	}
	
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Aug 24, 2007 7:45 am
by funguse
ok i think i've managed to get at least something.
(see code and images)

i want to get the value next to idle but dont quite know how i can do that. and also the value does not display on the output (image 2). any one know y that is?



image 1
image 2

Code: Select all

<? 
	$username='root';
	$password='sibi123';

	$header1=(	
				chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).chr(0xFB).chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).chr(0xFF).chr(0xFB).chr(0x27).chr(0xFF).chr(0xFD).chr(0x01).
				chr(0xFF).chr(0xFB).chr(0x03).chr(0xFF).chr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).chr(0x23).chr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).chr(0x1F).chr(0x00).chr(0x50).
				chr(0x00).chr(0x18).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).chr(0x00).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0x2C).chr(0x33).chr(0x38).chr(0x34).
				chr(0x30).chr(0x30).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).chr(0x54).chr(0x45).
				chr(0x52).chr(0x4D).chr(0xFF).chr(0xF0)
			); 
	
	$header2=(	
				chr(0xFF).chr(0xFC).chr(0x01).chr(0xFF).chr(0xFC).chr(0x22).chr(0xFF).chr(0xFE).chr(0x05).chr(0xFF).chr(0xFC).chr(0x21)
			);
	
	$fp=pfsockopen("172.19.1.38",23); 
	
	fputs($fp,$header1); 
	sleep(1); 
	fputs($fp,$header2); 
	sleep(1); 
	
	fputs($fp,"$username\r"); 
	sleep(1); 
	fputs($fp,"$password\r"); 
	sleep(1); 
	fputs($fp,"\r"); 
	sleep(3); 
	fputs($fp,"\r"); 
	sleep(3); 
	fputs($fp,"q \r"); 
	sleep(3); 
	fputs($fp,"topas \r"); 
	sleep(1); 
	
	$output=fread($fp,128); 
	$stat=socket_get_status($fp); 
	$output.=fread($fp, $stat["unread_bytes"]); 
	
	$output = explode("\n", $output); 
	unset($output['0']); 
	$output = implode("\n", $output); 
	
	$output = str_replace("\n", "<br>", $output); 
	echo $output; 
	fclose($fp); 
?>

Re: php and telnet (again)

Posted: Fri Aug 24, 2007 8:54 am
by volka
funguse wrote:the server is an IBM running AIX on the same network as the host server.
I can view the status by loggin into the server as root and using hummingbird (software) or using telnet.
What about ssh?

Posted: Fri Aug 24, 2007 9:04 am
by funguse
i tried ssh using the putty.exe client but connection via port 22 isnt allowed on the server :(

Posted: Fri Aug 24, 2007 9:14 am
by volka
You should ask the admin of that server. There's virtually no (good) reason to allow telnet but not ssh.