News... | Hack-Acad | Downloads | Web-Projekte | System-Check | Kontakt
HACKACAD - C# - IP Adresse erzeugen

Eine einfache Funktion die per Random eine Class A, B, C IP Adresse erzeugt:

 
using System;

namespace IPspoofing
{	
	class Class1
	{
		static void Main(string[] args)
		{
			string	cEnd, ipType;

			// Class A => 10.0.0.0    - 10.255.255.255
			// Class B => 172.16.0.0  - 172.31.255.255
			// Class C => 192.168.0.0 - 192.168.255.255
			
			Random iRand = new Random();
			ipType = "A";
			getSpoofed(ref iRand, ref ipType);			
			cout("Class A => " + ipType);
			ipType = "B";
			getSpoofed(ref iRand, ref ipType);			
			cout("Class B => " + ipType);
			ipType = "C";
			getSpoofed(ref iRand, ref ipType);			
			cout("Class C => " + ipType);
			ipType = "any";
			getSpoofed(ref iRand, ref ipType);			
			cout("any ip  => " + ipType);

			cout("\r\n<ENTER> zum beenden.");
			cEnd = Console.ReadLine();
		}

		private static void getSpoofed(ref Random iRand, ref string ipType)
		{
			string	cEnd, newIP = "";
			int		iNum = 0, iMin = 0, iMax = 0;

			switch(ipType)
			{
				case "A":
					iMin = 10;
					iMax = 172;
					break;
				case "B":
					iMin = 172;
					iMax = 192;
					break;
				case "C":
					iMin = 192;
					iMax = 254;
					break;
				default:
					iMin = 1;            
					iMax = 255;
					break;
			}  
			
			for (int i = 0; i < 4; i++)
			{
				if (i > 0 ) 
				{
					iMin = 0;					
					iMax = 255;
				}
				iNum = iRand.Next(iMin, iMax);
				newIP += iNum.ToString();
				if (i<3) newIP += ".";
			}
			
				ipType = newIP;
				newIP = "";			
		}

		private static void cout(string val)
		{
			Console.WriteLine(val);
		}
	}
}