PDA

View Full Version : حرفه ای: استفاده از دستوري مانند netstat در c#



amir4015
دوشنبه 02 مرداد 1391, 20:35 عصر
باسلام
دستوري مانند netstat رو زماني كه در cmd كامپيوتر وارد مي كنيد به سايت ها يا اي پي هاي كه وصل هستيم توسط هر مرور گر به ما نشون مي ده
حالا من مي خواستم يك برنامه بنويسم كه اين كار رو انجام بده
ممنون مي شم اكه راهنمايي كنيىد

amir4015
دوشنبه 02 مرداد 1391, 20:45 عصر
؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟

nunegandom
دوشنبه 02 مرداد 1391, 21:24 عصر
با سلام، شما برای اینکه نیای بری سوکت پروگرامینگ کار کنی، بهتره از خود cmd استفاده کنی، به این صورت که پروسس cmd رو تحت نظر بگیری دستور بهش ارسال کنی و جوابشو تویه یه فایل متنی ذخیره کنی و مورد استفاده قرار بدی
تویه همین انجمن دربارش بحث شده
یه سری کد دارم میذارم

// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "YOURBATCHFILE.bat";
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();

nunegandom
دوشنبه 02 مرداد 1391, 21:30 عصر
اینارو هم جمع کردم:

Bastane Port 445
netsh firewall delete portopening protocol = TCP port = 445

------------
Baz kardane port 445
netsh firewall add portopening protocol = TCP port = 445 name = "TCP/IP" mode = ENABLE scope = SUBNET

netsh firewall add portopening TCP 445 blah enable subnet

----------------
Sakhtane User Password jaded
net user username password /add
-------------------
erteQaie sathe dastresi ie user be administrator
net localgroup "administrators" username /add
-----------
Qeire fa’al kardane firewall
netsh firewall set opmode disable
-------------
Fa’al kardane firewall
netsh firewall set opmode enable

---------
Baz kardane ie port be surate ertebate amn
netsh firewall add portopening protocol = TCP port = 3389 name = "Terminal Service" mode = ENABLE scope = SUBNET

--------------
Active Remote Desktop:
In Win7
netsh advfirewall firewall set rule group="remote desktop" new enable=Yes

in XP:
netsh firewall set service RemoteDesktop enable

--------------

amir4015
دوشنبه 02 مرداد 1391, 21:42 عصر
ممنون دوست عزيز

amir4015
دوشنبه 02 مرداد 1391, 21:47 عصر
مي شه بيشتر توضيح بديد

nunegandom
دوشنبه 02 مرداد 1391, 22:27 عصر
Process p = new Process();
p.StartInfo.Arguments = "sfc /scannow";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
دیگه واضحه
این دقیقا برای sfc تنظیم شده، اطلاعات رو برمیگردونه تویه output

amir4015
دوشنبه 02 مرداد 1391, 22:45 عصر
دوست عزيز وقتي دستور ارسال مي كنم ارور مي ده

p.StandardInput.Write("netstat");

amir4015
سه شنبه 03 مرداد 1391, 14:17 عصر
?????????????????

amir4015
سه شنبه 03 مرداد 1391, 16:15 عصر
درست شد
نحوه ارسال به پروسس اينطوريه

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.Arguments = "sfc /scannow";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "cmd.exe";

p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;




p.Start();
p.StandardInput.WriteLine(@"Echo on");
p.StandardInput.WriteLine(@"netstat");

p.StandardInput.WriteLine(@"EXIT");
textBox1.Text = p.StandardOutput.ReadToEnd();
p.WaitForExit();

amir4015
سه شنبه 03 مرداد 1391, 16:17 عصر
nunegandom (http://barnamenevis.org/member.php?u=194035) ممنون به خاطر پاسخ هايي كه داديد

nunegandom
سه شنبه 03 مرداد 1391, 17:21 عصر
خواهش میکنم، ببخشید که دیر پاسخ میدم، خیلی کم میام انجمن :)