0

If I code a WHOIS server program, say using languages like C# and Java, what functionalities must I supply?

What I understand is, WHOIS servers listen to the port no. 43. When they receive a command "whois", they respond with various information pertaining to the server itself.

So, it's just a normal TCP/IP server that listens to a special port and serves a specific purpose.

Am I correct?

Whois Client:

using System;
using System.Net.Sockets;
using System.IO;
public class Whois
{
 static void Main(string[] args)
 {
 try
 {
 TcpClient client = new TcpClient();
 client.Connect("localHost", 43);
 if (args.Length < 1)
 {
 Console.WriteLine("Provide more than one Args");
 }
 else if (args.Length == 1)
 {
 StreamWriter sw = new StreamWriter(client.GetStream());
 StreamReader sr = new StreamReader(client.GetStream());
 sw.WriteLine(args[0]);
 sw.Flush();
 Console.WriteLine(args[0] + " is "+ sr.ReadToEnd()); 
return;
 }
 else if (args.Length > 1)
 {
 StreamWriter sw = new StreamWriter(client.GetStream());
 StreamReader sr = new StreamReader(client.GetStream());
 string str = "";
 foreach (string arg in args)
 {
 str += arg + " ";
 }
 sw.WriteLine(str);
 sw.Flush();
 Console.WriteLine(args[0] + " location changed to be " + args[1]);
 sw.Close();
 return;
 }
 else Console.WriteLine("Invalid args ");
 return;
 }
 catch (Exception e)
 {
 Console.WriteLine(e.Message);
 }
 }
} 

Whois Server:

using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Collections.Generic;

namespace locationserver
{
 public class respond
 {
 static Dictionary<string, string> SavedLocationa = new Dictionary<String, String>();
 static void Main(string[] args)
 {
 runServer();
 }
 static void runServer()
 {
 TcpListener listener;
 Socket connection;
 NetworkStream socketStream;
 try
 {
 listener = new TcpListener(IPAddress.Any, 43);
 listener.Start();
 Console.WriteLine("server started listening");
 while (true)
 {
 connection = listener.AcceptSocket();
 socketStream = new NetworkStream(connection);
 Console.WriteLine("Connection Received");
 doRequest(socketStream);
 socketStream.Close();
 connection.Close();
 }
 }
 catch (Exception e)
 {
 Console.WriteLine("Exception:" + e.ToString());
 }
 } 
static void doRequest(NetworkStream socketStream)
 {
 try
 {
 StreamWriter sw = new StreamWriter(socketStream);
 StreamReader sr = new StreamReader(socketStream);
 String line = sr.ReadLine();
 Console.WriteLine("Respond Received:" + line);
 String[] sections = line.Split(new char[] { ' ' }, 2);
 String names, location;
 if (line.Contains("-h0"))
 {
 Console.WriteLine(" Is ok");
 }
 else if (line.Contains("-h9"))
 {
 Console.WriteLine("Hey you're progressing");
 }
 else if (line.Contains("-h1"))
 {
 Console.WriteLine("We're Done");
 }
 if (sections.Length < 1)
 {
 Console.WriteLine("Too little words was inputted");
 }
 else if (sections.Length == 1)
 {
 names = sections[0];
 if (SavedLocationa.ContainsKey(names))
 {
 sw.WriteLine(SavedLocationa[names]);
 }
 else
 { 
sw.WriteLine("Error no entries found");
 }
 sw.Flush();
 Console.WriteLine("Error no entries found");
 }
 else if (sections.Length == 2)
 {
 names = sections[0];
 location = sections[1];
 if (SavedLocationa.ContainsKey(names))
 {
 SavedLocationa.Remove(names);
 }
 else
 {
 SavedLocationa.Add(names, location);
 sw.WriteLine("Update Successful");
 }
 sw.Flush();
 }
 }
 catch (Exception e)
 {
 Console.WriteLine("Something went wrong");
 Console.WriteLine(e.Message);
 }
 }
 }
} 

What functionalities are missing in the server portion of the code?

user366312
  • 16,949
  • 65
  • 235
  • 452
  • 1
    At least to me it is not clear what you are asking. RFC 812 does not demand anything specific about how a request has to be processed. – Klaus Gütter Feb 22 '20 at 14:05
  • "What functionalities are missing in the server portion of the code?" This completely depends first on why do you need to have a whois server at all? You will need to provide some more context. Also nowadays whois is kind of becoming obsolete in the presence of RDAP. You should look after doing an RDAP server instead, but again it depends what is really your context, what entity you are, what data you manage, who are your whois/RDAP clients, etc. – Patrick Mevzek Mar 09 '20 at 04:54
  • "they respond with various information pertaining to the server itself." The data in output is not about the server itself. It is about the data (ex: domain names, blocks of IP addresses, etc.) that the entity behind this server manages. This is the biggest part of explanation you do not provide in your question. – Patrick Mevzek Mar 09 '20 at 04:55

0 Answers0