C# 通过ipify接口获取外网IP地址

using (var client = new WebClient())
{

    client.Encoding = Encoding.UTF8;
    string serviceAddress = "https://api.ipify.org/?format=json";//请求URL地址
    var data = client.DownloadString(serviceAddress);
    var obj = JsonConvert.DeserializeObject<JObject>(data);

    string s = obj["ip"].ToString();
    Console.Write(s);
}
posted @ 2022-12-26 15:44  673613920  阅读(44)  评论(0编辑  收藏  举报