From: cikerblog
Form diagram:
Completion chart:
Only pasteCode:
Private void button#click (Object sender, eventargs E)
{
Textbox1.text = DNS. Resolve (DNS. gethostname (). Addresslist. getvalue (0). tostring (); // intranet IP Address
Textbox2.text = getip (); // Internet IP Address
}
static string getip ()
{< br> URI uri = new uri ("http://www.ciker.net/ip/index.asp");
system. net. httpwebrequest Req = (system. net. httpwebrequest) system. net. webrequest. create (URI);
req. method = "Post";
req. contenttype = "application/X-WWW-form-urlencoded";
req. contentlength = 0;
req. cookiecontainer = new system. net. cookiecontainer ();
req. getrequeststream (). write (New BYT E [0], 0, 0);
system. net. httpwebresponse res = (system. net. httpwebresponse) (req. getresponse ();
streamreader rs = new streamreader (res. getresponsestream (), system. text. encoding. getencoding ("gb2312");
string S = Rs. readtoend ();
Rs. close ();
req. abort ();
res. close ();
system. text. regularexpressions. match m = system. text. regularexpressions. regEx. match (S, @ "Your IP :(? [0-9 \.] *) ");
If (M. success)
{< br> return M. groups ["ip"]. value;
}< br> else
{< br> return "failed .. ";
}< BR >}