/*
 * Copyright 1999-2018 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.alibaba.nacos.naming.misc;

import com.alibaba.nacos.naming.boot.RunningConfig;

import java.net.InetAddress;
import java.net.UnknownHostException;

import static com.alibaba.nacos.common.util.SystemUtils.PREFER_HOSTNAME_OVER_IP;

/**
 * @author nacos
 */
public class NetUtils {

    public static String localServer() {
        try {
            if (PREFER_HOSTNAME_OVER_IP) {
                return InetAddress.getLocalHost().getHostName() + ":" + RunningConfig.getServerPort();
            } else {
                return InetAddress.getLocalHost().getHostAddress() + ":" + RunningConfig.getServerPort();
            }
        } catch (UnknownHostException e) {
            return "resolve_failed";
        }
    }

    public static String num2ip(int ip) {
        int[] b = new int[4];
        String x = "";

        b[0] = (int) ((ip >> 24) & 0xff);
        b[1] = (int) ((ip >> 16) & 0xff);
        b[2] = (int) ((ip >> 8) & 0xff);
        b[3] = (int) (ip & 0xff);
        x = Integer.toString(b[0]) + "." + Integer.toString(b[1]) + "." + Integer.toString(b[2]) + "." + Integer.toString(b[3]);

        return x;
    }


}

@@ -957,16 +957,147 @@
   try %7B%0A
+            InetAddress inetAddress = InetAddress.getLocalHost();%0A            String serverAddress = inetAddress.getHostAddress();%0A
         
@@ -1143,32 +1143,29 @@
             
-return I
+if (i
 netAddress.g
@@ -1170,69 +1170,124 @@
 .get
-LocalHost().getHostName() + %22:%22 + RunningConfig.getServerPort
+HostName().equals(inetAddress.getCanonicalHostName())) %7B%0A                    serverAddress = inetAddress.getHostName
 ();%0A
@@ -1298,16 +1298,20 @@
         
+ 
+   
 %7D else %7B
@@ -1331,16 +1331,29 @@
     
-return I
+    serverAddress = i
 netA
@@ -1366,42 +1366,135 @@
 .get
-Lo
+Canoni
 calHost
-().getHost
+Name();%0A                %7D%0A            %7D%0A            return server
 Address
-()
  + 
-%22:%22
+UtilsAndCommons.CLUSTER_CONF_IP_SPLITER
  + R
@@ -1523,30 +1523,16 @@
 Port();%0A
-            %7D%0A
         

support domain for server cluster into k8s