Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.98 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3.  
  4. $host = "192.168.1.100";
  5. $port = 80;
  6.  
  7. set_time_limit(0);
  8.  
  9. $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
  10. $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
  11. $result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
  12. $spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
  13.  
  14. $remote_host;
  15. $remote_port;
  16.  
  17. $local_host;
  18. $local_port;
  19.  
  20. socket_getpeername($spawn, $remote_host, $remote_port);
  21. socket_getsockname($spawn, $local_host, $local_port);
  22. echo("Got connection from: $remote_host on port $remote_port | Attached to $local_host on port $local_port \n");
  23. auth();
  24.  
  25. socket_close($socket);
  26.  
  27. function auth()
  28. {
  29.     global $spawn;
  30.  
  31.     socket_write($spawn, "Please enter your username: ");
  32.     $username = rtrim(socket_read($spawn, 1024));
  33.     if($username == "Lain")
  34.     {
  35.         echo("User $username logged in.\n");
  36.         motd();
  37.         prompt();
  38.     }
  39.     else
  40.     {
  41.         socket_write($spawn, "Invalid username. Closing connection.\nBye.");
  42.         socket_close($spawn);
  43.     }
  44. }
  45.  
  46. function motd()
  47. {
  48.     global $spawn;
  49.  
  50.     $motd = "  
  51.     _    _      _ _         _           _      
  52.       | |  | |    | | |       | |         (_)      
  53.       | |__| | ___| | | ___   | |     __ _ _ _ __  
  54.       |  __  |/ _ \ | |/ _ \  | |    / _` | | '_ \
  55.       | |  | |  __/ | | (_) | | |___| (_| | | | | |
  56.       |_|  |_|\___|_|_|\___/  |______\__,_|_|_| |_|\n\n";
  57.  
  58.     socket_write($spawn, $motd);
  59. }
  60.  
  61. function prompt()
  62. {
  63.     global $spawn;
  64.     socket_write($spawn, "Welcome to the wired...enter your command.\n");
  65.     do
  66.     {
  67.         socket_write($spawn, "> ");
  68.         $input = socket_read($spawn, 1024) or die("Could not read input\n");
  69.  
  70.         if(rtrim($input != ''))
  71.         {
  72.             if(rtrim($input) == "END")
  73.             {
  74.                 socket_write($spawn, "bye\n");
  75.                 socket_close($spawn);
  76.                 break;
  77.             }
  78.             else
  79.             {
  80.                 echo("Got $input");
  81.                 socket_write($spawn, "You said $input");
  82.             }
  83.         }
  84.     }
  85.     while(true);
  86. }
  87.  
  88.  
  89. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement