Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

C#ɨÃè¼ÆËã»ú¶Ë¿Ú

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace PortScanner
{
class Program
{
¡¡//ÒÑɨÃè¶Ë¿ÚÊýÄ¿
¡¡internal static int scannedCount = 0;
¡¡//ÕýÔÚÔËÐеÄÏß³ÌÊýÄ¿
¡¡internal static int runningThreadCount = 0;
¡¡//´ò¿ªµÄ¶Ë¿ÚÊýÄ¿
¡¡internal static List<int> openedPorts = new List<int>();
¡¡//ÆðʼɨÃè¶Ë¿Ú
¡¡static int startPort = 1;
¡¡//½áÊø¶Ë¿ÚºÅ
¡¡static int endPort = 500;
¡¡//×î´ó¹¤×÷Ïß³ÌÊý
¡¡static int maxThread = 10;
¡¡static void Main(string[] args)
¡¡{
¡¡¡¡//½ÓÊÕ´«Èë²ÎÊýÒ»×÷ΪҪɨÃèµÄÖ÷»ú
¡¡¡¡string host = "192.168.0.1";
¡¡¡¡//½ÓÊÕ´«Èë²ÎÊý¶þ×÷Ϊ¶Ë¿ÚɨÃ跶Χ£¬Èç1-4000
¡¡¡¡string portRange = "1-400";
¡¡¡¡startPort = int.Parse(portRange.Split('-')[0].Trim());
¡¡¡¡endPort = int.Parse(portRange.Split('-')[1].Trim());
¡¡¡¡for (int port = startPort; port < endPort; port++)
¡¡¡¡{
¡¡¡¡¡¡//´´½¨É¨ÃèÀà
¡¡¡¡¡¡Scanner scanner = new Scanner(host, port);
¡¡¡¡¡¡Thread thread = new Thread(new ThreadStart(scanner.Scan));
¡¡¡¡¡¡thread.Name = port.ToString();
¡¡¡¡¡¡ thread.IsBackground = true;
¡¡¡¡¡¡//Æô¶¯É¨ÃèÏß³Ì
¡¡¡¡¡¡thread.Start();
¡¡¡¡¡¡runningThreadCount++;
¡¡¡¡¡¡Thread.Sleep(10);
¡¡¡¡¡¡//Ñ­»·£¬Ö±µ½Ä³¸öÏ̹߳¤×÷Íê±Ï²ÅÆô¶¯ÁíÒ»ÐÂỊ̈߳¬Ò²¿ÉÒÔ½Ð×öÍÆÀ­´°¼¼Êõ
¡¡¡¡¡¡while (runningThreadCount >= maxThread) ;
¡¡¡¡}
¡¡¡¡//¿ÕÑ­»·£¬Ö±µ½ËùÓж˿ÚɨÃèÍê±Ï
¡¡¡¡while (scannedCount + 1 < (endPort - startPort)) ;
¡¡¡¡¡¡Console.WriteLine();
¡¡¡¡¡¡Console.WriteLine();
¡¡¡¡¡¡//Êä³ö½á¹û
¡¡¡¡¡¡Console.WriteLine("Scan for host: {0} has been completed , \n total {1} ports scanned, \nopened ports :{2}",
host, (endPort - startPort), openedPorts.Count);
¡¡¡¡foreach (int port in openedPorts)
¡¡¡¡¡¡Console.WriteLine("\tPort: {0} is open", port.ToString().PadLeft(6));
¡¡}
}
//ɨÃèÀà
class Scanner
{
¡¡string m_host;
¡¡int m_port;
¡¡
¡¡public Scanner(string host, int port)
¡¡{
¡¡¡¡m_h


Ïà¹ØÎĵµ£º

C#ÖÐref²ÎÊýÓëout²ÎÊýµÄÇø±ð

ÏÈÌù´úÂë
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ref_and_Out_test
{
    class Program
    {
        static void Main(string[] args)
      & ......

Ìá¸ßC#±à³ÌˮƽµÄ50¸öÒª¾÷


ÏëÌá¸ßc#±à³Ìˮƽ£¿ÏÂÃæÕâ50Ìõ¾­Ñé²»¿É²»¶Á£¡
Ìá¸ßC#±à³ÌˮƽµÄ50¸öÒªµã
1.×ÜÊÇÓÃÊôÐÔ (Property) À´´úÌæ¿É·ÃÎʵÄÊý¾Ý³ÉÔ±
2.ÔÚ  readonly ºÍ const Ö®¼ä£¬ÓÅÏÈʹÓà readonly
3.ÔÚ as ºÍ Ç¿ÖÆÀàÐÍת»»Ö®¼ä£¬ÓÅÏÈʹÓà as ²Ù×÷·û
4.ʹÓÃÌõ¼þÊôÐÔ (Conditional Attributes) À´´úÌæÌõ¼þ±àÒëÓï¾ä #if
5.×ÜÊÇΪ×Ô¶¨Ò ......

c#Ïß³Ì

c#ÖÐдһ¸ö¶àÏß³ÌÓ¦ÓÃÊǷdz£¼òµ¥µÄ£¬±¾Õ½«½éÉÜÈçºÎÔÚc#ÖÖ¿ª·¢¶àÏ̳߳ÌÐò¡£ÔÚ.netÖÐÏß³ÌÊÇÓÉSystem.Threading Ãû×Ö¿Õ¼äËù¶¨ÒåµÄ¡£ËùÒÔÄã±ØÐë°üº¬Õâ¸öÃû×ֿռ䡣
using System.Threading;
¿ªÊ¼Ò»¸öÏß³Ì
System.Threading Ãû×Ö¿Õ¼äµÄÏß³ÌÀàÃèÊöÁËÒ»¸öÏ̶߳ÔÏó£¬Í¨¹ýʹÓÃÀà¶ÔÏó£¬Äã¿ÉÒÔ´´½¨¡¢É¾³ý¡¢Í£Ö¹¼°»Ö¸´Ò»¸öÏ̡߳£ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ