Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php
- <?php
- $host = "192.168.1.100";
- $port = 80;
- set_time_limit(0);
- $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
- $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
- $result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
- $spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
- $remote_host;
- $remote_port;
- $local_host;
- $local_port;
- socket_getpeername($spawn, $remote_host, $remote_port);
- socket_getsockname($spawn, $local_host, $local_port);
- echo("Got connection from: $remote_host on port $remote_port | Attached to $local_host on port $local_port \n");
- auth();
- socket_close($socket);
- function auth()
- {
- global $spawn;
- socket_write($spawn, "Please enter your username: ");
- $username = rtrim(socket_read($spawn, 1024));
- if($username == "Lain")
- {
- echo("User $username logged in.\n");
- motd();
- prompt();
- }
- else
- {
- socket_write($spawn, "Invalid username. Closing connection.\nBye.");
- socket_close($spawn);
- }
- }
- function motd()
- {
- global $spawn;
- $motd = "
- _ _ _ _ _ _
- | | | | | | | | | (_)
- | |__| | ___| | | ___ | | __ _ _ _ __
- | __ |/ _ \ | |/ _ \ | | / _` | | '_ \
- | | | | __/ | | (_) | | |___| (_| | | | | |
- |_| |_|\___|_|_|\___/ |______\__,_|_|_| |_|\n\n";
- socket_write($spawn, $motd);
- }
- function prompt()
- {
- global $spawn;
- socket_write($spawn, "Welcome to the wired...enter your command.\n");
- do
- {
- socket_write($spawn, "> ");
- $input = socket_read($spawn, 1024) or die("Could not read input\n");
- if(rtrim($input != ''))
- {
- if(rtrim($input) == "END")
- {
- socket_write($spawn, "bye\n");
- socket_close($spawn);
- break;
- }
- else
- {
- echo("Got $input");
- socket_write($spawn, "You said $input");
- }
- }
- }
- while(true);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement