Click here to Skip to main content
15,885,309 members
Articles / Programming Languages / C#

Remote Shutdown or Reboot with Telnet and C#

Rate me:
Please Sign up or sign in to vote.
2.11/5 (14 votes)
17 Oct 20042 min read 149.2K   5K   55  
Reboot a computer remotely with Telnet on port 50000, written in C#.
using System;
using System.Security.Cryptography;
using System.Text;

class makeconfig
{
    static void Main(String[] args)
    {

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<configuration>\n   <appSettings>\n        <add key=\"PasswordMD5\" value=\"");
        sb.Append(hash(getinput("Enter Password")));
        sb.Append("\" />\n      <add key=\"Port\" value=\"");
        sb.Append(getinput("Enter Port"));
        sb.Append("\" />\n	</appSettings>\n</configuration>");
        System.Console.WriteLine();
        System.Console.WriteLine(sb.ToString());

        System.Console.WriteLine("This output is also contained in the file RemoteShutdown.exe.config.New remove the .New after putting it in the appropriate bin directory.\n");
        System.IO.StreamWriter sw=new System.IO.StreamWriter("RemoteShutdown.exe.config.new");
        sw.Write(sb.ToString());
        sw.Close();
    }

    private static string getinput(string text)
    {
        System.Console.WriteLine(text);
        return System.Console.ReadLine();
    }

    private static string hash(string text)
    {
        string strHash = "";
        byte[] data, enc;

        data = Encoding.Default.GetBytes(text);
        SHA1 sha1 = new SHA1Managed();
        enc = sha1.TransformFinalBlock(data, 0, data.Length);
        foreach (byte b in sha1.Hash)
            strHash += Convert.ToString(b, 16).ToUpper().PadLeft(2, '0');
        sha1.Clear();
        return strHash;
    }
}
 

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
I have been programming since 1983 when I first programmed on a HeathKit 8088 Breadboard Computer in machine code. Since then I have dabbled with many things. I am extremely fluent with VB6, Access, Sql Server. I am currently programming a major project in C#.

I am also a system administrator for Unix, Linux, MS 4.0 - 2003 and also dabble with CISCO routers and firewalls.

Comments and Discussions