Create License File and save with Host Name,MAC ID,IP and Processor ID from ASP.NET


protected void Btncreat_Click(object sender, EventArgs e)
    {
         string sFileName = System.IO.Path.GetRandomFileName();
        string sGenName = "Licence.lic";
        IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
        IPAddress[] addr = ipEntry.AddressList;
        //YOu could omit these lines here as you may
        //not want to save the textfile to the server
        //I have just left them here to demonstrate that you could create the text file
        using (System.IO.StreamWriter SW = new System.IO.StreamWriter(
               Server.MapPath("TextFiles/" + sFileName + ".lic")))
        {
            SW.WriteLine("Your Host Name is : " + Dns.GetHostName().ToString());
            SW.WriteLine("SERVER IP is : " + addr[2].ToString());
            SW.WriteLine("Your System MAC Address is : " + GetMacAddress().ToString());
            SW.WriteLine("Your System Processor ID is : " + System.Diagnostics.Process.GetCurrentProcess().Id);
            SW.Close();
        }

        System.IO.FileStream fs = null;
        fs = System.IO.File.Open(Server.MapPath("TextFiles/" +
                 sFileName + ".lic"), System.IO.FileMode.Open);
        byte[] btFile = new byte[fs.Length];
        fs.Read(btFile, 0, Convert.ToInt32(fs.Length));
        fs.Close();
        Response.AddHeader("Content-disposition", "attachment; filename=" +
                           sGenName);
        Response.ContentType = "application/octet-stream";
        Response.BinaryWrite(btFile);
        Response.End();
       
    }

Comments

Popular posts from this blog

All about SSP in MOSS 2007

Request.QueryString() for Javascript (ver. 1.41)