[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] PHP-Novice, PING??



2009/10/4 Ole Kofoed Hansen <sslug@sslug>

> Søren Sørensen skrev:
>
>> Nogen gode ideer til hvad jeg gør galt?
>>
>
> Du gør det galt, at du prøver at åbne en rå socket uden at være root.
>
> Grunden til at det virker for dig, når du kører ping på en commandline er,
> at ping har setuid-bit sat, så det program kører faktisk som root.
>
> Med venlig hilsen
>
> Ole
>

Alle er enige om at "SOCK_RAW" er forbeholdt root, og det er apache-serveren
ikke. Derfor fik jeg en anden lys idé. Alle de maskiner jeg skal overvåge
har en åben port til ssh (port 22), så jeg lavede mit PHP-program om til:

  echo "making socket<br>";
 $socket = socket_create(AF_INET, SOCK_STREAM, 1);
 echo "Trying to connect<br>";
 $result=socket_connect($socket, "127.0.0.1", 22);
 echo "resultat: ".$result;
 echo "<br>reading<br>";
 if (socket_read($socket, 255))
  {
  echo "Got something<br>";
  }

Det var dog heller ikke succes, det endte igen med:

  making socket
Trying to connect
resultat:
reading

Så klippede jeg en bid ud af et gammelt c-program fra 2005:

struct sockaddr_in address;
struct in_addr inaddr;
struct hostent *host;

char *ipaddr="127.0.0.1";
char *portnr="22";

host=gethostbyname( ipaddr )
tel_sockfd=socket(PF_INET, SOCK_STREAM, 0)
address.sin_family = AF_INET;
address.sin_port=htons(atoi(portnr));
memcpy( &address.sin_addr, host->h_addr_list[0], sizeof(address.sin_addr));
if( connect( tel_sockfd, (struct sockaddr *) &address, sizeof(address) ))
  {
   printf( "Init... Beklager - kunne ikke oprette forbindelse til
utility-port\n" );
   exit(1);
   }
while( read( tel_sockfd, &charac, 1 ) > 0 ) printf( "%c", charac);


Og den kommer pænt og siger "SSH-2.0-OpenSSH_4.5"

Det var det jeg så skrækkelig gerne ville have PHP-programmet til at gøre
også.

M.v.h.

Søren


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2009-11-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *