Up to date

This page is up to date for Godot 4.1. If you still find outdated information, please open an issue.

IP

Inherits: Object

Internet protocol (IP) support functions such as DNS resolution.

Description

IP contains support functions for the Internet Protocol (IP). TCP/IP support is in different classes (see StreamPeerTCP and TCPServer). IP provides DNS hostname resolution support, both blocking and threaded.

Methods

void

clear_cache ( String hostname=”” )

void

erase_resolve_item ( int id )

PackedStringArray

get_local_addresses ( ) const

Dictionary[]

get_local_interfaces ( ) const

String

get_resolve_item_address ( int id ) const

Array

get_resolve_item_addresses ( int id ) const

ResolverStatus

get_resolve_item_status ( int id ) const

String

resolve_hostname ( String host, Type ip_type=3 )

PackedStringArray

resolve_hostname_addresses ( String host, Type ip_type=3 )

int

resolve_hostname_queue_item ( String host, Type ip_type=3 )


Enumerations

enum ResolverStatus:

ResolverStatus RESOLVER_STATUS_NONE = 0

DNS hostname resolver status: No status.

ResolverStatus RESOLVER_STATUS_WAITING = 1

DNS hostname resolver status: Waiting.

ResolverStatus RESOLVER_STATUS_DONE = 2

DNS hostname resolver status: Done.

ResolverStatus RESOLVER_STATUS_ERROR = 3

DNS hostname resolver status: Error.


enum Type:

Type TYPE_NONE = 0

Address type: None.

Type TYPE_IPV4 = 1

Address type: Internet protocol version 4 (IPv4).

Type TYPE_IPV6 = 2

Address type: Internet protocol version 6 (IPv6).

Type TYPE_ANY = 3

Address type: Any.


Constants

RESOLVER_MAX_QUERIES = 256

Maximum number of concurrent DNS resolver queries allowed, RESOLVER_INVALID_ID is returned if exceeded.

RESOLVER_INVALID_ID = -1

Invalid ID constant. Returned if RESOLVER_MAX_QUERIES is exceeded.


Method Descriptions

void clear_cache ( String hostname=”” )

Removes all of a hostname‘s cached references. If no hostname is given, all cached IP addresses are removed.


void erase_resolve_item ( int id )

Removes a given item id from the queue. This should be used to free a queue after it has completed to enable more queries to happen.


PackedStringArray get_local_addresses ( ) const

Returns all the user’s current IPv4 and IPv6 addresses as an array.


Dictionary[] get_local_interfaces ( ) const

Returns all network adapters as an array.

Each adapter is a dictionary of the form:

  1. {
  2. "index": "1", # Interface index.
  3. "name": "eth0", # Interface name.
  4. "friendly": "Ethernet One", # A friendly name (might be empty).
  5. "addresses": ["192.168.1.101"], # An array of IP addresses associated to this interface.
  6. }

String get_resolve_item_address ( int id ) const

Returns a queued hostname’s IP address, given its queue id. Returns an empty string on error or if resolution hasn’t happened yet (see get_resolve_item_status).


Array get_resolve_item_addresses ( int id ) const

Returns resolved addresses, or an empty array if an error happened or resolution didn’t happen yet (see get_resolve_item_status).


ResolverStatus get_resolve_item_status ( int id ) const

Returns a queued hostname’s status as a ResolverStatus constant, given its queue id.


String resolve_hostname ( String host, Type ip_type=3 )

Returns a given hostname’s IPv4 or IPv6 address when resolved (blocking-type method). The address type returned depends on the Type constant given as ip_type.


PackedStringArray resolve_hostname_addresses ( String host, Type ip_type=3 )

Resolves a given hostname in a blocking way. Addresses are returned as an Array of IPv4 or IPv6 addresses depending on ip_type.


int resolve_hostname_queue_item ( String host, Type ip_type=3 )

Creates a queue item to resolve a hostname to an IPv4 or IPv6 address depending on the Type constant given as ip_type. Returns the queue ID if successful, or RESOLVER_INVALID_ID on error.