Port nedir sorusunun cevabını buradan bulabilirsiniz. Bilgisayarınızda bulunan 65535 porttan hangileri açık hangileri kapalı görmek için C# da bir program yazacağız. Port tarama işlemi yavaş gerçekleşen bir olaydır. 65 bin portun hepsinin taranması uzun sürecektir. Kodların en başında bulunan portStart ve portStop intager değişkenlerine taramak istediğiniz portların aralığını girebilirsiniz.
Program sadece sizin bilgisayarınızdaki portları taramaz. Açılışta istenen ip adresine başka bir bilgisayarın ip adresi girilirse o bilgisayarın açık portlarını tarar ve gösterir. Sadece yerel ağda çalışır.
Kodlar:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
using System; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading; namespace PortScanner { class Program { static void Main(string[] args) { string host; int portStart = 1, portStop = 65535, ctrThread = 200; try { Console.WriteLine("Taranacak İp Adresi:"); host = Console.ReadLine(); } catch { printUsage(); return; } PortScanner ps = new PortScanner(host, portStart, portStop); ps.start(ctrThread); } static void printUsage() { Console.WriteLine("0 - 65535 tüm portları tarar.\n"); } } public class PortScanner { private string host; private PortList portList; public PortScanner(string host, int portStart, int portStop) { this.host = host; this.portList = new PortList(portStart, portStop); } public PortScanner(string host) : this(host, 1, 65535) { } public PortScanner() : this("127.0.0.1") { } public void start(int threadCtr) { for (int i = 0; i < threadCtr; i++) { Thread th = new Thread(new ThreadStart(run)); th.Start(); } } public void run() { int port; TcpClient tcp = new TcpClient(); while ((port = portList.getNext()) != -1) { try { tcp = new TcpClient(host, port); } catch { continue; } finally { try { tcp.Close(); } catch { } } Console.WriteLine("TCP Port " + port + " açık."); } } } public class PortList { private int start; private int stop; private int ptr; public PortList(int start, int stop) { this.start = start; this.stop = stop; this.ptr = start; } public PortList() : this(1, 65535) { } public bool hasMore() { return (stop - ptr) >= 0; } public int getNext() { if (hasMore()) return ptr++; return -1; } } } |
Not: Kod açık kaynak bir sistemden alıntıdır. Düzenlenip ihtiyaca göre ayarlanmıştır.
Proje Dosyası: https://github.com/fatihyldrim/OpenPortScan/
Biraz yavaş tarıyor ama güzel program olmuş
Siteniz çok güzel. İlgili kişiler için kolay ve dikkat çekici bilgiler içeriyor. Hatta yol gösterici. Yalnız yazı ekleme periyodunuz çok az sanki.