• Source
    1. using System;
    2. using System.Net;
    3. using System.Text;
    4.  
    5. namespace NCSIResponder
    6. {
    7. class Program
    8. {
    9. private static string NCSI_RESPONSE = "Microsoft NCSI";
    10. private static byte[] NCSI_RESPONSE_BYTE = Encoding.UTF8.GetBytes(NCSI_RESPONSE);
    11.  
    12. static void Main(string[] args)
    13. {
    14. var listener = new HttpListener();
    15. listener.Prefixes.Add("http://127.0.0.1/");
    16. listener.Start();
    17. while (true)
    18. {
    19. var context = listener.GetContext();
    20. var request = context.Request;
    21. Console.WriteLine("[" + DateTime.Now + "] " + request.RemoteEndPoint.Address + " - " + request.Url);
    22. if (request.RawUrl == "/ncsi.txt")
    23. {
    24. context.Response.StatusCode = 200;
    25. context.Response.OutputStream.Write(NCSI_RESPONSE_BYTE, 0, NCSI_RESPONSE_BYTE.Length);
    26. context.Response.Close();
    27. }
    28. else
    29. {
    30. context.Response.StatusCode = 404;
    31. context.Response.Close();
    32. }
    33. }
    34. }
    35. }
    36. }