diff --git a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/lib/mysql/AzureMySQLService.java b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/lib/mysql/AzureMySQLService.java index 71c3f6af11..3bd3144477 100644 --- a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/lib/mysql/AzureMySQLService.java +++ b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/lib/mysql/AzureMySQLService.java @@ -14,22 +14,24 @@ import com.microsoft.azure.toolkit.intellij.connector.mysql.MySQLConnectionUtils; import com.microsoft.azure.toolkit.lib.Azure; import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation; +import com.microsoft.azure.toolkit.lib.common.utils.NetUtils; import com.microsoft.azure.toolkit.lib.resource.AzureGroup; import com.microsoft.azuretools.ActionConstants; import com.microsoft.azuretools.authmanage.AuthMethodManager; -import com.microsoft.azuretools.azurecommons.util.GetHashMac; import com.microsoft.azuretools.core.mvp.model.mysql.MySQLMvpModel; import com.microsoft.azuretools.telemetry.TelemetryConstants; -import com.microsoft.azuretools.telemetrywrapper.*; +import com.microsoft.azuretools.telemetrywrapper.ErrorType; +import com.microsoft.azuretools.telemetrywrapper.EventType; +import com.microsoft.azuretools.telemetrywrapper.EventUtil; +import com.microsoft.azuretools.telemetrywrapper.Operation; +import com.microsoft.azuretools.telemetrywrapper.TelemetryManager; import org.apache.commons.lang3.StringUtils; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.net.URL; import java.net.HttpURLConnection; +import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; @@ -168,12 +170,8 @@ public boolean disableAllowAccessFromLocalMachine(final String subscriptionId, f } private String getAccessFromLocalRuleName() { - String hostname = "UNKNOWN_HOST"; - try { - hostname = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - } - final String macAddress = GetHashMac.getMac(); + final String hostname = NetUtils.getHostName(); + final String macAddress = NetUtils.getMac(); final String ruleName = NAME_PREFIX_ALLOW_ACCESS_TO_LOCAL + hostname + "_" + macAddress; return ruleName; } diff --git a/Utils/azuretools-core/src/com/microsoft/azuretools/azurecommons/util/GetHashMac.java b/Utils/azuretools-core/src/com/microsoft/azuretools/azurecommons/util/GetHashMac.java index 9bc9509278..b0bef10358 100644 --- a/Utils/azuretools-core/src/com/microsoft/azuretools/azurecommons/util/GetHashMac.java +++ b/Utils/azuretools-core/src/com/microsoft/azuretools/azurecommons/util/GetHashMac.java @@ -61,21 +61,6 @@ public static String getHashMac() { return ret; } - public static String getMac() { - try { - InetAddress ip = InetAddress.getLocalHost(); - NetworkInterface network = NetworkInterface.getByInetAddress(ip); - byte[] mac = network.getHardwareAddress(); - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < mac.length; i++) { - sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : "")); - } - return sb.toString(); - } catch (UnknownHostException | SocketException e) { - return null; - } - } - private static boolean isValidMac(String mac) { if (StringUtils.isEmpty(mac)) { return false;