如何在Windows应用商店应用中获取本地主机IP地址? [英] How do I get the local host IP address in a Windows Store app?

查看:236
本文介绍了如何在Windows应用商店应用中获取本地主机IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows应用商店应用中调用的特定休息服务需要将呼叫计算机的IP地址作为参数。使用 System.Net System.Net.NetworkInformation 在商店应用程序中编译。

A particular rest service I am calling in a Windows Store app wants the IP address of the calling computer as a parameter. None of the tried and true examples using System.Net or System.Net.NetworkInformation compile in a Store app.

Windows商店中可用的类型和方法的神奇组合是什么将获得本地计算机的IP地址的应用程序?我觉得这可能很明显,但我没有看到它!

What is the magical combination of types and methods available in a windows store app that will get to the local machine's IP address? I feel like it is probably obvious but I am not seeing it!

推荐答案

本地网络IP地址:

foreach (HostName localHostName in NetworkInformation.GetHostNames())
{
    if (localHostName.IPInformation != null)
    {
        if (localHostName.Type == HostNameType.Ipv4)
        {
            // E.g.: 192.168.1.108
            Debug.WriteLine(localHostName);
        }
    }
}

这篇关于如何在Windows应用商店应用中获取本地主机IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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