XML class serializer in C#

Filed Under (c#) by The Chef on 06-06-2009

Tagged Under : , , , ,

Here it is a short class very useful for serializing and deserializing. This is a good for settings file or configuration files.

using System.Xml.Serialization;
using System.IO;
using System.Text;

namespace XMLData
{
    public static class ObjectXMLSerializer<T> where T : class
    {
        public static T Load(string path)
        {
            T mRet = null;

            using (TextReader textReader = new StreamReader(path))
            {
                XmlSerializer mXmlSerializer = new XmlSerializer(typeof(T));
                mRet = mXmlSerializer.Deserialize(textReader) as T;
            }

            return mRet;
        }

        public static void Save(T serializableObject, string path)
        {
            using (TextWriter mTextWriter = new StreamWriter(path))
            {
                XmlSerializer mXmlSerializer = new XmlSerializer(typeof(T));
                mXmlSerializer.Serialize(mTextWriter, serializableObject);
            }
        }
        public static T LoadString(string mString)
        {
            T mRet = null;

            using (MemoryStream textReader = new MemoryStream(Encoding.ASCII.GetBytes(mString)))
            {
                XmlSerializer mXmlSerializer = new XmlSerializer(typeof(T));
                mRet = mXmlSerializer.Deserialize(textReader) as T;
            }

            return mRet;
        }
    }
}

Here it is a short usage example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            links lnk = new links();
            lnk.str = "something";
            lnk.integer = 23;
            lnk.floatnumber = 0.23f;
            lnk.stringlist.Add("element 1");
            lnk.stringlist.Add("element 2");
            lnk.stringlist.Add("element 3");
            //save class to xml
            XMLData.ObjectXMLSerializer<links>.Save(lnk, @"c:\test.xml");
            //load class from xml
            lnk = XMLData.ObjectXMLSerializer<links>.Load(@"c:\test.xml");
        }

    }

    [Serializable]
    public class links
    {
        public String str;
        public int integer;
        public float floatnumber;
        public List<string> stringlist = new List<string>();
    }
}

and this is the xml it produces:

<?xml version="1.0" encoding="utf-8"?>
<links xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <str>something</str>
  <integer>23</integer>
  <floatnumber>0.23</floatnumber>
  <stringlist>
    <string>element 1</string>
    <string>element 2</string>
    <string>element 3</string>
  </stringlist>
</links>

Finding DNS servers using c#

Filed Under (c#, net) by The Chef on 06-06-2009

Tagged Under : , ,

Every computer connected to the internet must interrogate a DNS server in order to resolve domain names to ip addresses. To find the DNS server addresses your computer uses to resolve names, either it has a dhcp or static ip address, you can use the following piece of code. I wrapped all around a nice static class for ease of use.

   public static class DNSFinder
   {
       private static List<String> mServers = new List<string>();
       public static List<String> Servers
       {
           get
           {
               RegistryKey start = Registry.LocalMachine;
               string DNSservers = @"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters";
               RegistryKey DNSserverKey = start.OpenSubKey(DNSservers);
               if (DNSserverKey != null)
               {
                   // Static ip address
                   string serverlist = (string)DNSserverKey.GetValue("NameServer");
                   string[] servers = serverlist.Split(' ');
                   foreach (string server in servers)
                   {
                       mServers.Add(server);
                   }
                   //dhcp assigned address
                   serverlist = (string)DNSserverKey.GetValue("DhcpNameServer");
                   servers = serverlist.Split(' ');
                   foreach (string server in servers)
                   {
                       mServers.Add(server);
                   }
                   start.Close();
               }
               DNSserverKey.Close();
               return mServers;
           }
       }

Short guide on detecting invisible yahoo users

Filed Under (Guides) by The Chef on 06-06-2009

Tagged Under : , , , , , , ,

These days it’s very popular especially for high-school teenagers to chat over yahoo messenger and other programs using same yahoo messenger protocol. Inevitably there had appeared programs and services related to yahoo messenger: tools, skins, emoticons and not the last invisible detectors. There are 2 kind of invisible yahoo scanners: web-based and stand-alone. There are a few stand-alone versions but there are dozens of web-based ones. I will focus on the web-based invisible scanners. The big majority are from Middle East (especially Iran) and Eastern Europe (especially Romania). I guess the target users are from the same regions. The whole buzz started out about a year or a year and a half ago and since then, there was a flood of new sites. So let’s see what’s inside a invisible scanner site: an interface and a background scanning architecture.

  • Interface: is mostly simple the main element being a text input and a scan button. The results are displayed using  ajax and can contain the status, avatar, cartoon avatar, and some shortcuts to profiles like hi5 and 360 and also shortcuts for adding scanned person to the yahoo messenger buddy list or sending an instant message. Most interfaces are bloated with comercials and use colors resembling yahoo colors and icons.
  • Scanning architecture: is in all cases based on bots and may be of 3 kinds depending on the type of bots.
    1. Persistent bots. The botnet is always logged in to yahoo and acts like legit yahoo messenger clients.
    2. On-the-fly logging bots. These bots are write in server side programming language mostly php and are logging in only when they had an scanning request and logout after finishing the scan.
    3. Stolen bots. The great majority of the sites use the bots of another sites

Now it cames to the basic users to decide which one is the best, but I will only look for the reliability  and speed of the scans. Knowing this, think twice when you try to stay invisible on yahoo messenger because it’s no longer invisible !

Get yahoo invisible scanner script

Page 3 of 101234510...Last »