2024年6月14日发(作者:)

Visual C#得到本机外网IP地址

2008-12-14 12:26:52| 分类:C# | 标签:c#|字号大中小订阅

(程序通过该.xml配置可查询IP的网站)

/

GB18030

您的IP地址是:[(?<IP>[0-9.]*)]

using System;

using c;

using entModel;

using ;

using g;

using ;

using ;

using ;

using ;

using ;

namespace GetIP

{

public partial class Form1 : Form

{

private string str_HostName = , str_Encode = , str_RegularExpressions =

;

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

try

{

ReadConfig();

= GetIP();

}

catch (ion ex)

{

= e;

}

}

private string GetIP()

{

Uri uri = new Uri(@str_HostName);

HttpWebRequest req = (HttpWebRequest)(uri);

= "POST";

tType = "application/x-www-form-urlencoded";

tLength = 0;

Container = new Container();

uestStream().Write(new byte[0], 0, 0);

HttpWebResponse res = (HttpWebResponse)(ponse());

StreamReader rs = new StreamReader(ponseStream(),

oding(@str_Encode));

string s = End();

();

();

();

m = (s,

@str_RegularExpressions);

if (s)

return ["IP"].Value;

else

return "无法查询IP";

}

private void ReadConfig()

{

string s = ;

XmlNodeReader reader = null;

try

{

XmlDocument myConfig = new XmlDocument();

(tDirectory+@"");

reader = new XmlNodeReader(myConfig);

while (())

{

switch (pe)

{

case t:

s = ;

break;

case :

if (("HostName"))

str_HostName = ;

else if (("Encode"))

str_Encode = ;

else if (("RegularExpressions"))

str_RegularExpressions = ;

break;

}

}

}

finally

{

if (reader != null) ();

}

}

}

}