第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用 azure sdk 獲取 vm 公共 IP?

如何使用 azure sdk 獲取 vm 公共 IP?

C#
UYOU 2022-06-18 16:25:42
我使用Microsoft.Azure.Compute.Fluentsdk 列出了我所有的虛擬機(jī),它工作正常,除了我無(wú)法獲取公共 IP 地址:    IVirtualMachines _client = azure.VirtualMachines;     var list = await _client.ListAsync();    foreach (var instance in list)    {        var name = instance.Name;        var ip = instance.GetPrimaryPublicIPAddress().IPAddress;        //ip = null here;    }好吧,我嘗試了其他東西,但總是將公共 ip 設(shè)為空。如何正確檢索公共 IP?
查看完整描述

1 回答

?
鳳凰求蠱

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊

如果我誤解了你,請(qǐng)糾正我:我找不到 sdk Microsoft.Azure.Compute.Fluent(截圖如下):

http://img1.sycdn.imooc.com//62ad8c200001736f11750312.jpg

所以我改用這個(gè)sdk Microsoft.Azure.Management.Fluent(官方文檔也使用它)。并且可以在我身邊獲取ip,代碼如下:


using Microsoft.Azure.Management.Compute.Fluent;

using Microsoft.Azure.Management.Fluent;

using Microsoft.Azure.Management.ResourceManager.Fluent;

using Microsoft.Azure.Management.ResourceManager.Fluent.Core;

using System;

using System.Threading.Tasks;


namespace myVMDotnetProject

{

    class Program

    {

        static void Main(string[] args)

        {

            GetVMInfo();


            Console.WriteLine("okok");

            Console.ReadLine();

        }



        static async Task  GetVMInfo()

        {

            var credentials = SdkContext.AzureCredentialsFactory.FromFile(Environment.GetEnvironmentVariable("AZURE_AUTH_LOCATION", EnvironmentVariableTarget.User));


            var azure = Azure

                .Configure()

                .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)

                .Authenticate(credentials)

                .WithDefaultSubscription();


            IVirtualMachines _client = azure.VirtualMachines;

            var list = await _client.ListAsync();


            foreach (var instance in list)

            {

                var name = instance.Name;

                var ip = instance.GetPrimaryPublicIPAddress().IPAddress;

                Console.WriteLine("name: " + name + ", ip: " + ip);

            }

        }


    }

}

測(cè)試結(jié)果如下:

http://img1.sycdn.imooc.com//62ad8c34000107db16160874.jpg

查看完整回答
反對(duì) 回復(fù) 2022-06-18
  • 1 回答
  • 0 關(guān)注
  • 161 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)