在C#中的外部IP地址 [英] external IP-address in C#

查看:148
本文介绍了在C#中的外部IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是让我的外部IP地址在C#中最简单的方法是什么?

What is the easiest way to get my external IP-address in C#?

推荐答案

有没有内置的方式来做到这一点的框架内,因为很难确定外部/公共IP地址是什么。当然,这是假设你的IP是背后的一些网关NAT映射

There's no built-in way to do it within the framework because it's hard to determine what the external/public IP address is. This of course is assuming your IP is NAT'ed behind some gateway.

一个方法是刮喜欢的 http://www.whatismyip.org/ 使用的 WebClient的类。

One method would be to scrape a site like http://www.whatismyip.org/ using the WebClient class.

System.Net.WebClient client = new System.Net.WebClient();
string ip = client.DownloadString( "http://www.whatismyip.org" );
Console.Out.WriteLine( ip );

这篇关于在C#中的外部IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆