荔枝大娘

C# 获取真实IP地址

电脑版发表于:2020/4/30 9:32
//192.168开头的IP是一个代理Ip并不是你真实的IP

  public string GetRelayIP()
        {
            WebClient myWebClient = new WebClient();
            myWebClient.Credentials = CredentialCache.DefaultCredentials;

            byte[] pageData = myWebClient.DownloadData("https://www.ip38.com/");
            string pageHtml = Encoding.UTF8.GetString(pageData);

            pageHtml = pageHtml.Replace('\'', '\"');
            pageHtml = pageHtml.Replace("ip", "\"ip\"");
            pageHtml = pageHtml.Replace("address", "\"address\"");

            //根据返回会来的html进行切割 定位到ip
            string pram = "<a href=/\"ip\".php?\"ip\"";
            string[] arr = pageHtml.Split(pram.ToCharArray());

            string strtempa = "=";
            string strtempb = ">";

            string ipstr = arr[1];

            int IndexofA = ipstr.IndexOf(strtempa);
            int IndexofB = ipstr.IndexOf(strtempb);
            string ip = ipstr.Substring(IndexofA + 1, IndexofB - IndexofA - 1);

            return ip;
        }


关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢