所以我试图创建一个应用程序,告诉你你的公共IP地址,我已经让它工作,但是当离线它只是打破程序,我想让它在文本框中说“没有连接”而不是刚破坏......这就是我到目前为止所做的。
private string getMyIPAddress()
{
string Address = "";
WebRequest request = WebRequest.Create("http://checkip.dyndns.com");
using (WebResponse response = request.GetResponse())
using (StreamReader stream = new StreamReader(response.GetResponseStream()))
{
Address = stream.ReadToEnd();
}
int first = Address.IndexOf("Address: ") + 9;
int last = Address.IndexOf("</body>");
Address = Address.Substring(first, last - first);
textBox4.Text = Address;
return Address;
}