Click here to Skip to main content
15,896,207 members
Articles / Programming Languages / Visual Basic

UDP Client and Server and Remote BSOD prank too!

Rate me:
Please Sign up or sign in to vote.
2.68/5 (15 votes)
16 Feb 20058 min read 106.9K   3.7K   24  
Demonstrates how to use a UDP client, and a UDP server. The example is named "Remote BSOD Invocator", or simply RBSOD for short. RBSOD can be used to trigger fake (and funny) BSODs on your colleagues' (or enemies') computers.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Indy.Sockets;

namespace RBSOD {
	public class Form1 : System.Windows.Forms.Form {
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Button butnShow;
    private System.Windows.Forms.TextBox textHost;
    private System.Windows.Forms.Button butnClear;
    private System.Windows.Forms.CheckBox chckAnyKey;
    private System.Windows.Forms.CheckBox chckShowTrademark;
    private System.Windows.Forms.CheckBox chckCustomMsg;
    private System.Windows.Forms.TextBox textCustomMsg;
    private System.Windows.Forms.ListBox lboxMsgs;
		private System.ComponentModel.Container components = null;

		public Form1() {
			InitializeComponent();
      lboxMsgs.SelectedIndex = 0;
		}

		protected override void Dispose( bool disposing ) {
			if( disposing ) {
				if (components != null) {
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
      this.butnShow = new System.Windows.Forms.Button();
      this.label1 = new System.Windows.Forms.Label();
      this.textHost = new System.Windows.Forms.TextBox();
      this.butnClear = new System.Windows.Forms.Button();
      this.chckAnyKey = new System.Windows.Forms.CheckBox();
      this.chckShowTrademark = new System.Windows.Forms.CheckBox();
      this.chckCustomMsg = new System.Windows.Forms.CheckBox();
      this.textCustomMsg = new System.Windows.Forms.TextBox();
      this.lboxMsgs = new System.Windows.Forms.ListBox();
      this.SuspendLayout();
      // 
      // butnShow
      // 
      this.butnShow.Location = new System.Drawing.Point(272, 32);
      this.butnShow.Name = "butnShow";
      this.butnShow.TabIndex = 0;
      this.butnShow.Text = "&Show";
      this.butnShow.Click += new System.EventHandler(this.button1_Click);
      // 
      // label1
      // 
      this.label1.Location = new System.Drawing.Point(8, 8);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(208, 23);
      this.label1.TabIndex = 1;
      this.label1.Text = "&IP Address (Leave blank for broadcast)";
      // 
      // textHost
      // 
      this.textHost.Location = new System.Drawing.Point(8, 32);
      this.textHost.Name = "textHost";
      this.textHost.Size = new System.Drawing.Size(256, 20);
      this.textHost.TabIndex = 2;
      this.textHost.Text = "";
      // 
      // butnClear
      // 
      this.butnClear.DialogResult = System.Windows.Forms.DialogResult.Cancel;
      this.butnClear.Location = new System.Drawing.Point(272, 64);
      this.butnClear.Name = "butnClear";
      this.butnClear.TabIndex = 3;
      this.butnClear.Text = "&Clear";
      this.butnClear.Click += new System.EventHandler(this.butnClear_Click);
      // 
      // chckAnyKey
      // 
      this.chckAnyKey.Location = new System.Drawing.Point(8, 56);
      this.chckAnyKey.Name = "chckAnyKey";
      this.chckAnyKey.Size = new System.Drawing.Size(112, 24);
      this.chckAnyKey.TabIndex = 4;
      this.chckAnyKey.Text = "Ask for &any key";
      // 
      // chckShowTrademark
      // 
      this.chckShowTrademark.Location = new System.Drawing.Point(144, 56);
      this.chckShowTrademark.Name = "chckShowTrademark";
      this.chckShowTrademark.Size = new System.Drawing.Size(120, 24);
      this.chckShowTrademark.TabIndex = 5;
      this.chckShowTrademark.Text = "Show &trademark";
      // 
      // chckCustomMsg
      // 
      this.chckCustomMsg.Location = new System.Drawing.Point(8, 80);
      this.chckCustomMsg.Name = "chckCustomMsg";
      this.chckCustomMsg.Size = new System.Drawing.Size(168, 24);
      this.chckCustomMsg.TabIndex = 6;
      this.chckCustomMsg.Text = "&Use a custom message";
      this.chckCustomMsg.CheckedChanged += new System.EventHandler(this.chckCustomMsg_CheckedChanged);
      // 
      // textCustomMsg
      // 
      this.textCustomMsg.Location = new System.Drawing.Point(8, 104);
      this.textCustomMsg.Name = "textCustomMsg";
      this.textCustomMsg.Size = new System.Drawing.Size(256, 20);
      this.textCustomMsg.TabIndex = 7;
      this.textCustomMsg.Text = "<Enter your custom message here>";
      this.textCustomMsg.Visible = false;
      // 
      // lboxMsgs
      // 
      this.lboxMsgs.Items.AddRange(new object[] {
                                                  "A fatal exception OE has occurred at 0028:C0011E36 in VXD VMM(01)00010E36. The cu" +
                                                  "rrent application will be terminated.",
                                                  "A file that big? It might be very useful.But now it is gone.",
                                                  "The Web site you seek Can not be located but Countless more exist.",
                                                  "Chaos reigns within. Reflect, repent, and reboot. Order shall return.",
                                                  "Serious error. All shortcuts have disappeared. Screen. Mind. Both are blank.",
                                                  "Windows crashed again. I am the Blue Screen of Death. No one hears your screams.",
                                                  "Yesterday it worked. Today it is not working. Windows is like that.",
                                                  "Stay the patient course. Of little worth is your ire. The network is down.",
                                                  "A crash reduces Your expensive computer To a simple stone.",
                                                  "Three things are certain: Death, taxes, and lost data. Guess which has occurred.",
                                                  "You step in the stream, But the water has moved on. This page is not here.",
                                                  "Out of memory. We wish to hold the whole sky, But we never will.",
                                                  "Having been erased, The document you\'re seeking Must now be retyped",
                                                  "First snow, then silence. This thousand dollar screen dies So beautifully.",
                                                  "The Tao that is seen Is not the true Tao, until You bring fresh toner",
                                                  "With searching comes loss And the presence of absence: \"My Novel\" not found.",
                                                  "ABORTED effort: Close all that you have worked on. You ask way too much."});
      this.lboxMsgs.Location = new System.Drawing.Point(8, 136);
      this.lboxMsgs.Name = "lboxMsgs";
      this.lboxMsgs.Size = new System.Drawing.Size(328, 134);
      this.lboxMsgs.TabIndex = 8;
      // 
      // Form1
      // 
      this.AcceptButton = this.butnShow;
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.CancelButton = this.butnClear;
      this.ClientSize = new System.Drawing.Size(352, 273);
      this.Controls.Add(this.lboxMsgs);
      this.Controls.Add(this.textCustomMsg);
      this.Controls.Add(this.chckCustomMsg);
      this.Controls.Add(this.chckShowTrademark);
      this.Controls.Add(this.chckAnyKey);
      this.Controls.Add(this.butnClear);
      this.Controls.Add(this.textHost);
      this.Controls.Add(this.label1);
      this.Controls.Add(this.butnShow);
      this.Name = "Form1";
      this.Text = "RBSOD Client";
      this.ResumeLayout(false);

    }
		#endregion

		[STAThread]
		static void Main() {
			Application.Run(new Form1());
		}

    private void button1_Click(object sender, System.EventArgs e) {
      string s = "";
      if (chckCustomMsg.Checked) {
        if (s != "<Enter your custom message here>") {
          s = textCustomMsg.Text.Trim();
        }
      } else {
        s = lboxMsgs.Text;
      }
      if (s != "") {
        SendMsg(s);
      }
    }

    private void SendMsg(string aMsg) {
      using (UDPClient xClient = new UDPClient()) {
        xClient.Host = textHost.Text.Trim();
        xClient.Port = 6001;
        xClient.Send(aMsg);
      }
    }

    private void butnClear_Click(object sender, System.EventArgs e) {
      SendMsg("");
    }

    private void chckCustomMsg_CheckedChanged(object sender, System.EventArgs e) {
      textCustomMsg.Visible = chckCustomMsg.Checked;
    }
	}
}

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
Cyprus Cyprus
Chad Z. Hower, a.k.a. Kudzu
"Programming is an art form that fights back"

I am a former Microsoft Regional DPE (MEA) covering 85 countries, former Microsoft Regional Director, and 10 Year Microsoft MVP.

I have lived in Bulgaria, Canada, Cyprus, Switzerland, France, Jordan, Russia, Turkey, The Caribbean, and USA.

Creator of Indy, IntraWeb, COSMOS, X#, CrossTalk, and more.

Comments and Discussions