c#获取外网IP地址的方法
1.如果你是通过路由上网的,可以通过访问ip138之类的地址来获取外网IP
2.如果是通过PPPOE拨号上网的,可以使用以下代码获取IP
//获取宽带连接(PPPOE拨号)的IP地址,timeout超时(秒),当宽带未连接或者连接中的时候获取不到IP
public static string GetIP_PPPOE(int timeout)
{
int i = timeout * 2;
while (i > 0)
{
try
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
bool havePPPOE = false;
foreach (NetworkInterface adapter in nics)
{
if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ppp)
{
havePPPOE = true;
IPInterfaceProperties ip = adapter.GetIPProperties(); //IP配置信息
if (ip.UnicastAddresses.Count > 0)
{
return ip.UnicastAddresses[0].Address.ToString();
}
}
}
//当没有宽带连接的时候直接返回空
if (!havePPPOE) return "";
}
catch (Exception ex)
{
Console.WriteLine("获取宽带拨号IP出错:" + ex.Message);
}
i--;
Thread.Sleep(500);
}
return "";
}
c#获取外网IP地址的方法的更多相关文章
- java获取外网ip地址
转自:http://blog.163.com/houjunchang_daxue/blog/static/13037938320134543310451/ /** * 获取外网IP.归属地.操作系统 ...
- C# 获取外网IP地址
很多情况下我们需要获取外网的IP地址,一般用自带的方法获取到的都是不准确,往往获取到的是内网的IP地址,所以需要采用外部网站接口来获取. 代码 通过访问第三方接口来获取真实的ip地址 public s ...
- MFC C++ 获取外网IP地址
#include <afxinet.h> //GB2312 转换成 Unicode wchar_t* GB2312ToUnicode(const char* szGBString) { U ...
- linux 获取外网ip地址
curl ifconfig.me 私有ip地址,获取公网ip
- android 根据网络来获取外网ip地址及国家,地区的接口
新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 新浪多地域测试方法:http://int.dpool. ...
- 服务器查看外网IP地址和方法
返回IP地址 curl ip..com/ip.aspx curl whatismyip.akamai.com wget -qO - ifconfig.co curl icanhazip.com dig ...
- C# Winform程序获取外网IP地址
string strUrl = "http://www.ip138.com/ip2city.asp"; //获得IP的网址了 Uri uri = new Uri(strUrl); ...
- 获取外网IP地址
public static string GetRealIP(){ string result = String.Empty; result = HttpC ...
- C#获取外网IP地址;C#获取所在IP城市地址
public static string GetIP() { using (var webClient = new WebClient()) ...
随机推荐
- 函数:MySQL中字符串匹配函数LOCATE和POSITION使用方法
1. 用法一 LOCATE(substr,str) POSITION(substr IN str) 函数返回子串substr在字符串str中第一次出现的位置.如果子串substr在str中不存在,返回 ...
- Windows API Hooking in Python
catalogue . 相关基础知识 . Deviare API Hook Overview . 使用ctypes调用Windows API . pydbg . winappdbg . dll inj ...
- PAT Basic Level 1001
大纲考察内容 数据存储结构:数组.链 基础算法:递归.排序.计算时间复杂度.空间复杂度.分析算法稳定性 1001.害死人不偿命的(3n+1)猜想 (15) https://www.patest.cn/ ...
- MDK5 STM32编译问题汇总
MDK5 STM32编译问题汇总 WIN8.KEIL-MDK-5 编译时,出现弹窗"The ARM C/C++ Compiler 已停止工作",关闭弹窗后,编译输出的窗口中出现如下 ...
- BZOJ3196: Tyvj 1730 二逼平衡树
传送门 主席树的常数蜜汁优越,在BZOJ上跑了rnk1. 做法很简单,主席树套BIT. 1-3做法很简单,第四个和第五个做法转换成前两个就行了. //BZOJ 3196 //by Cydiater / ...
- WA题集
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...
- IT这一行,如可高速下载国外资源之迅雷设置免费SSH代理下载国外资源
本文转自SUN'S BLOG 原文地址:IT这一行,如可高速下载国外资源之迅雷 我们这些做IT这一行的人,经常,下载一些国外的一些资源,可是让人蛋碎的是,往往这些资源下载都慢的像蜗牛,真的让人无法忍受 ...
- Visual Studio 2010 下 安装RGiesecke.DllExport
RGiesecke.DllExport 在 UnmanagedExports 中.安装过程如下: 1.首先在"工具"菜单下的"扩展管理器"中,安装 NuGet ...
- vue 组建实现数据的双向绑定
<!DOCTYPE html><html><head> <style>body { font-family: Helvetica Neue, Aria ...
- checkbox全选与非全选之间的切换
<div id="congras_area"> <input type="checkbox" name="" id=&qu ...