<commit_before>/*
 * 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);<commit_msg>support domain for server cluster into k8s<commit_after>/*
 * 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 {
            InetAddress inetAddress = InetAddress.getLocalHost();
            String serverAddress = inetAddress.getHostAddress();
            if (PREFER_HOSTNAME_OVER_IP) {
                if (inetAddress.getHostName().equals(inetAddress.getCanonicalHostName())) {
                    serverAddress = inetAddress.getHostName();
                } else {
                    serverAddress = inetAddress.getCanonicalHostName();
                }
            }
            return serverAddress + UtilsAndCommons.CLUSTER_CONF_IP_SPLITER + 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);
{'fraction_non_alphanumeric': 0.10011709601873536, 'fraction_numerical': 0.013173302107728338, 'mean_word_length': 2.763215859030837, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1087679', 'n_tokens_mistral': 1010, 'n_tokens_neox': 952, 'n_words': 297}