c#获取外网IP地址
生活随笔
收集整理的這篇文章主要介紹了
c#获取外网IP地址
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/// <summary>
? ? ? ? /// 獲取外網IP地址
? ? ? ? /// </summary>
? ? ? ? /// <returns></returns>
? ? ? ? public static string GetLocalIp()
? ? ? ? {
? ? ? ? ? ? string ip = "";
? ? ? ? ? ? string result = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
? ? ? ? ? ? if (null == result || result == String.Empty)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? result = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
? ? ? ? ? ? }
? ? ? ? ? ? if (null == result || result == String.Empty)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? result = System.Web.HttpContext.Current.Request.UserHostAddress;
? ? ? ? ? ? }
? ? ? ? ? ? return result;
? ? ? ? }
? ? ? ? /// 獲取外網IP地址
? ? ? ? /// </summary>
? ? ? ? /// <returns></returns>
? ? ? ? public static string GetLocalIp()
? ? ? ? {
? ? ? ? ? ? string ip = "";
? ? ? ? ? ? string result = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
? ? ? ? ? ? if (null == result || result == String.Empty)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? result = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
? ? ? ? ? ? }
? ? ? ? ? ? if (null == result || result == String.Empty)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? result = System.Web.HttpContext.Current.Request.UserHostAddress;
? ? ? ? ? ? }
? ? ? ? ? ? return result;
? ? ? ? }
總結
以上是生活随笔為你收集整理的c#获取外网IP地址的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《马克思主义基本原理概论》第 1 章世界
- 下一篇: (纪中)2162. 方格纸(square