根據我的經驗,我認爲您可以嘗試使用Azure SDK for Java從WebSiteManagementClient
獲取主機的內部IP地址。
以下是獲取內部IP地址的示例代碼。
String userName = "<user-name>";
String password = "<password>";
String resourceGroupName = "<resource-group-name>";
String name = "<webapp-name>";
ServiceClientCredentials credentials = new BasicAuthenticationCredentials(userName, password);
WebSiteManagementClient webSiteManagementClient = new WebSiteManagementClientImpl(credentials);
HostingEnvironmentsOperations hostingEnvironmentsOperations = webSiteManagementClient.getHostingEnvironmentsOperations();
ServiceResponse<AddressResponse> serviceResponse = hostingEnvironmentsOperations.getHostingEnvironmentVips(resourceGroupName, name);
AddressResponse addressResponse = (AddressResponse) serviceResponse.getBody();
String internalIp = addressResponse.getInternalIpAddress();
要運行上述示例,您需要將相關庫添加到Maven項目中,請參閱下面的依賴關係。
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-svc-mgmt-websites</artifactId>
<version>0.9.2</version>
</dependency>
有關上述示例代碼中關鍵類的更多詳細信息,請參閱下面的內容。
- WebSiteManagementClient & WebSiteManagementClientImpl
- HostingEnvironmentsOperations
- AddressResponse
謝謝@Peter。雖然這可能是一個解決方法,但它需要修改JGroups來檢測IP地址。我們可以修改JGroups代碼,但是如何打開防火牆以允許在JGroups端口7600上進行入站?這可能在Azure應用服務中嗎?對於Azure V2來說,SDK也發生了變化 - https://github.com/Azure/azure-sdk-for-java。 –