码迷,mamicode.com
首页 > Windows程序 > 详细

C#hhah

时间:2016-07-09 19:28:59      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TestIP
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
this.richTextBox1.Clear();
string iphostname = System.Net.Dns.GetHostName();
//会警告GetHostByName()已过期,我运行时且只返回了一个IPv4的地址
//System.Net.IPAddress[] ipaddress = System.Net.Dns.GetHostByName(iphostname).AddressList;
// //会返回所有地址,包括IPv4和IPv6
System.Net.IPAddress[] ipaddress = System.Net.Dns.GetHostAddresses(iphostname);
if (ipaddress != null && ipaddress.Length > 0)
{
foreach (System.Net.IPAddress ip in ipaddress)
{
this.richTextBox1.Focus();
SendKeys.Send(ip.ToString());
SendKeys.Send("{ENTER}");
}
}
}

private void button2_Click(object sender, EventArgs e)
{
this.richTextBox1.Clear();
string iphostname = System.Net.Dns.GetHostName();
System.Net.IPHostEntry iphostentry = System.Net.Dns.GetHostEntry(iphostname);
System.Net.IPAddress[] ipaddress = iphostentry.AddressList;
if (ipaddress != null && ipaddress.Length > 0)
{
foreach (System.Net.IPAddress ip in ipaddress)
{
this.richTextBox1.Focus();
SendKeys.Send(ip.ToString());
SendKeys.Send("{ENTER}");
}
}
}

private void button3_Click(object sender, EventArgs e)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "ipconfig.exe";
process.StartInfo.Arguments = "/all";
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
//process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
//关于:ProcessWindowStyle.Hidden隐藏后如何再显示?
//hwndWin32Host = Win32Native.FindWindow(null, win32Exinfo.windowsName);
//Win32Native.ShowWindow(hwndWin32Host, 1);
//先FindWindow找到窗口后再ShowWindow

 

}
}
}

C#hhah

标签:

原文地址:http://www.cnblogs.com/1175429393wljblog/p/5656357.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!