HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/primordial/constants.py
# -*- coding: utf-8 -*-

"""This module holds constants needed for primordial."""

try:
    import fcntl
except ImportError:
    pass  # Windows
import ipaddress
import struct
import socket


CANONICAL_TIMESTRING_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
"Standard format for time strings."
CANONICAL_TIMESTRING_FORMAT_NO_ZULU = '%Y-%m-%dT%H:%M:%S.%f'
"Standard format for time strings without a trailing Z."
CANONICAL_TIMESTRING_FORMAT_NO_MICROSECONDS = '%Y-%m-%dT%H:%M:%SZ'
"Strandard format for time strings without microseconds."


def getIP() -> str:
    """Get the IP address of this machine."""
    try:
        ips = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")]
        if ips:
            for ip in ips:
                if ipaddress.ip_address(str(ip)).is_private:
                    return ip
            return ips[0]
    except socket.gaierror:
        pass

    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        ipstr = struct.pack('256s'.encode('ascii'), 'eth0'.encode('ascii'))
        return socket.inet_ntoa(
            fcntl.ioctl(s.fileno(), 0x8915, ipstr)[20:24])
    except (IOError, RuntimeError, socket.gaierror):
        return '127.0.0.1'


IP = getIP()
"The IP address of this machine on which this is running."