Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System;
  2. using System.Net.Sockets;
  3. using System.IO;
  4.  
  5. public class Whois {
  6.     static void Main(string[] args) {
  7.         string username = args[0];
  8.         string location = string.Empty;
  9.         string IP = "whois.net.dcs.hull.ac.uk";
  10.         int port = 43;
  11.  
  12.         TcpClient client = new TcpClient();
  13.         StreamWriter sw = new StreamWriter(client.GetStream());
  14.         StreamReader sr = new StreamReader(client.GetStream());
  15.         client.Connect(IP, port);
  16.  
  17.         try {
  18.             //Read current location
  19.             if (args.Length == 1) {
  20.                 sw.WriteLine(args[0]);
  21.                 sw.Flush();
  22.                 location = sr.ReadToEnd();
  23.                 Console.WriteLine(username + " is " + location);
  24.             }
  25.             //Write new location
  26.             else if (args.Length > 0) {
  27.                 int i = 1;
  28.                 //Console.Write(username + " location changed to "); **Commented out as job done by line 37
  29.                 //Loop through array to get location
  30.                 while (i < args.Length) {
  31.                     //Console.Write(args[i] + " ");  **Don't write to console, write to location string instead
  32.                     location = location + args[i];
  33.                     i++;
  34.                 }
  35.                 sw.Flush(); //## ISN'T WRITING NEW LOCATION TO SERVER
  36.                 //Console.WriteLine(username + " location successfully updated to " + location); *******TEMP COMMENT OUT TO TEST line 37
  37.                 Console.WriteLine(username + " location successfully updated to " + sr.ReadToEnd());
  38.             }
  39.         }
  40.         catch {
  41.             Console.WriteLine("No entries found for user " + username);
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement