Friday, February 26, 2010

How to Check DNS with CSharp?

If you want to know any domain name is matched with certain ip address, you can use System.Net namespace to retrieve IPAddresses collection which is related to domain name. Please check the code snippet written below :
   1:  public static bool CheckDNS(string domain)
   2:  {
   3:      bool result = false;
   4:      try
   5:      {
   6:         IPAddress[] addressList = Dns.GetHostAddresses(domain);
   7:   
   8:         result = addressList.length > 0 ? true : false;
   9:      }
  10:      catch
  11:      {
  12:          result = false;
  13:      }
  14:  }
If  CheckDNS method returns true, it means domain name is related to at least one ip address. If return false, the domain name is not associated to any ip address.

For testing you can pass an existed domain name such as www.technolatte.net and pass a domain name which doesn't exist.

CheckDNS("www.technolatte.net"); //output is true
CheckDNS("www.thisistestdomainname.com"); //output is false

Thursday, February 25, 2010

Retrieving Serial Number of BIOS

Nowadays, i have been working on Windows Desktop Application. In this project, i need to match application's serial number and BIOS' serial number to prevent illegal usage. To retrieve BIOS number of computer i  used WMI Classes with .NET Framework namespace called System.Management. If you need to retrieve Serial Number of BIOS you can use following code snippet :
   1:  ManagementObjectSearcher wmiQuery = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
   2:  ManagementObjectCollection wmiColl = wmiQuery.Get();
   3:   
   4:  foreach (ManagementObject item in wmiColl)
   5:  {
   6:     Console.WriteLine(item.GetPropertyValue("SerialNumber"));
   7:  }
If you want to check other properties' name of Win32_BIOS, click to see link written below :
http://msdn.microsoft.com/en-us/library/aa394077(VS.85).aspx

Tuesday, February 9, 2010

Adding .flv MIME Type into IIS

For web pages, flv files is one of the best video displaying solution with flash player. As a default settings, flv mime type is not added in IIS. Although your flv file exists in your web server, you may see 404 not found response sent by web server.
For supporting flv extension in your web server, there is one settings you should apply. It's really simple. Check the following steps :
  1. Open IIS manager in your web server.
  2. Right click on your web site directory in the IIS and click properties.
  3. Find HTTP Headers tab and click on it.
  4. Click on MIME Types button.
  5. Type .flv into Extension textbox then videx/x-flv into MIME Type textbox.
  6. Finally, click OK button. Now, it's ready.
For more information about other MIME types, you can read the web page below which contains MIME Media Types.