28 Kasım 2017 Salı

C# Subnet Maneger & Ağ Tarama ve İşlem Yapma Programı

Hiç yorum yok
C# Subnet Maneger yani Ağ Tarama ve İşlem Yapma Programı düzenledim alt ağları tarayarak internetinize bağlı ağdaki bilgisayarları gösterip , yönetici izininiz olması durumunda üzerlerinde işlem yapmanıza olanak tanıyor.


C# Subnet Maneger Taramadan Sonra İşlem Yapma Penceresi Sağ tıktadır.

Örnek İşlem Komutu



Aşağıdaki kütüphane kodlarını projenize ekleyiniz.

1
2
3
4
5
6
7
using System.Net.NetworkInformation;
using System.Threading;
using System.Net;
using System.Management;
using System.Diagnostics;
using Microsoft.Win32;
using System.IO;


Ardından bütün kodlar bu şekilde Projenizin gerekli yerlerine yapıştırırsınız artık takıldınız yer olursa yorum yazabilirsiniz.
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
namespace Subnet_Manager
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            lblStatus.ForeColor = System.Drawing.Color.Red;
            lblStatus.Text = "BOŞ";
            Control.CheckForIllegalCrossThreadCalls = false;
        }
        Thread myThread = null;
        public void scan(string subnet)
        {
            Ping myPing;
            PingReply reply;
            IPAddress addr;
            IPHostEntry host;
            progressBar1.Maximum = 254;
            progressBar1.Value = 0;
            listVAddr.Items.Clear();
            for (int i = 1; i < 255; i++)
            {
                string subnetn = "." + i.ToString();
                myPing = new Ping();
                reply = myPing.Send(subnet + subnetn, 900);
                lblStatus.ForeColor = System.Drawing.Color.Green;
                lblStatus.Text = "Taranıyor: " + subnet + subnetn;
                if (reply.Status == IPStatus.Success)
                {
                    try
                    {
                        addr = IPAddress.Parse(subnet + subnetn);
                        host = Dns.GetHostEntry(addr);
                        listVAddr.Items.Add(new ListViewItem(new String[] { subnet + subnetn, host.HostName, "Hazır" }));
                    }
                    catch {listBox1.Items.Add("" + subnet + subnetn+ " için ana makine adı alınamadı"); }
                }
                progressBar1.Value += 1;
            }
            cmdScan.Enabled = true;
            cmdStop.Enabled = false;
            txtIP.Enabled = true;
            lblStatus.Text = "Bitti!";
            int count = listVAddr.Items.Count;
            MessageBox.Show("Tarama Tamamlandı!\n " + count.ToString() + " Host Bulundu.", "Tamamlandı", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        public void query(string host)
        {
            
            string temp = null;
            string[] _searchClass = { "Win32_ComputerSystem", "Win32_OperatingSystem", "Win32_BaseBoard", "Win32_BIOS" };
            string[] param = { "UserName", "Caption", "Product", "Description" };
            lblStatus.ForeColor = System.Drawing.Color.Green;
            for (int i = 0; i <= _searchClass.Length - 1; i++)
            {
                lblStatus.Text = "Bilgi Alınıyor.";
                try
                {
                    ManagementObjectSearcher searcher = new ManagementObjectSearcher("\\\\" + host + "\\root\\CIMV2", "SELECT *FROM " + _searchClass[i]);
                    foreach (ManagementObject obj in searcher.Get())
                    {
                        lblStatus.Text = "Bilgi Alınıyor. .";
                        temp += obj.GetPropertyValue(param[i]).ToString() + "\n";
                        if (i == _searchClass.Length - 1)
                        {
                            lblStatus.Text = "Tamamlandı!";
                            MessageBox.Show(temp, "Host Bilgisi: " + host, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            break;
                        }
                        lblStatus.Text = "Bilgi Alınıyor. . .";
                    }
                }
                catch (Exception ex) { MessageBox.Show("WMI sorgusunda hata.\n\n" + ex.ToString(), "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error); break; }
            }
        }
        public void controlSys(string host, int flags)
        {
            #region
            /*
             *Flags:
             *  0 (0x0)Log Off
             *  4 (0x4)Forced Log Off (0 + 4)
             *  1 (0x1)Shutdown
             *  5 (0x5)Forced Shutdown (1 + 4)
             *  2 (0x2)Reboot
             *  6 (0x6)Forced Reboot (2 + 4)
             *  8 (0x8)Power Off
             *  12 (0xC)Forced Power Off (8 + 4)
             */
            #endregion
            try
            {
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("\\\\" + host + "\\root\\CIMV2", "SELECT *FROM Win32_OperatingSystem");
                foreach (ManagementObject obj in searcher.Get())
                {
                    ManagementBaseObject inParams = obj.GetMethodParameters("Win32Shutdown");
                    inParams["Flags"] = flags;
                    ManagementBaseObject outParams = obj.InvokeMethod("Win32Shutdown", inParams, null);
                }
            }
            catch (ManagementException manex) { MessageBox.Show("Error:\n\n" + manex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            catch (UnauthorizedAccessException unaccex) { MessageBox.Show("Yetkili?\n\n" + unaccex.ToString(), "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
        private void cmdScan_Click(object sender, EventArgs e)
        {
            if (txtIP.Text == string.Empty)
            {
                MessageBox.Show("IP Adresi Girilmedi.", "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                myThread = new Thread(() => scan(txtIP.Text));
                myThread.Start();
                if (myThread.IsAlive == true)
                {
                    cmdStop.Enabled = true;
                    cmdScan.Enabled = false;
                    txtIP.Enabled = false;
                }
            }
        }
        private void cmdStop_Click(object sender, EventArgs e)
        {
            myThread.Suspend();
            cmdScan.Enabled = true;
            cmdStop.Enabled = false;
            txtIP.Enabled = true;
            lblStatus.ForeColor = System.Drawing.Color.Red;
            lblStatus.Text = "Boş";
        }
        private void listVAddr_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (listVAddr.FocusedItem.Bounds.Contains(e.Location) == true)
                {
                    conMenuStripIP.Show(Cursor.Position);
                }
            }    
        }
        private void cmdScan_Click_1(object sender, EventArgs e)
        {
            if (txtIP.Text == string.Empty)
            {
               listBox1.Items.Add("IP Adresi Girilmedi.");
            }
            else
            {
                myThread = new Thread(() => scan(txtIP.Text));
                myThread.Start();
                if (myThread.IsAlive == true)
                {
                    cmdStop.Enabled = true;
                    cmdScan.Enabled = false;
                    txtIP.Enabled = false;
                }
            }
        }
        private void cmdStop_Click_1(object sender, EventArgs e)
        {
            myThread.Suspend();
            cmdScan.Enabled = true;
            cmdStop.Enabled = false;
            txtIP.Enabled = true;
            lblStatus.ForeColor = System.Drawing.Color.Red;
            lblStatus.Text = "BOŞ";
        }
        private void showInfoToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            try
            {
                string host = listVAddr.SelectedItems[0].Text.ToString();
            Thread qThread = new Thread(() => query(host));
            qThread.Start();
            }
            catch (Exception hata)
            {
                MessageBox.Show("Hata Aldınız IP adresi seçtiğinize emin olunuz eğer seçtiyseniz alttaki hatayı inceleyin"+hata);
            }
          
        }
        private void kapatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string host = listVAddr.SelectedItems[0].Text.ToString();
            controlSys(host, 5);
        }
        private void yenidenBaşlatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string host = listVAddr.SelectedItems[0].Text.ToString();
            controlSys(host, 6);
        }
        private void gücüKapatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string host = listVAddr.SelectedItems[0].Text.ToString();
            controlSys(host, 12);
        }
        private void yardımToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Program birkaç şekilde kullanılabilir ilk olarak LAN daki diğer bilgisayarları bulup yetkiniz dahilinde bunlar üzerinde kapat yeniden başlat sistem bilgisi öğrenebilirsizin ikinci olaraktan ise alt ağlarında hangi siteler bulunduğunu merak ettiğiniz sunucuların alt ağlarına bakabilirsiniz.");
        }
        private void hakkımdaToolStripMenuItem_Click(object sender, EventArgs e)
        {
        
            
        }
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("http://sefayilmazz.blogspot.com.tr");
        }
    }
}

Hiç yorum yok :

Yorum Gönder

b2b yazılım vois media