# getType() function · @imqueue/net

Source: https://imqueue.org/api/net/latest/net.gettype/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/net 3.0.2 — generated reference, not hand-written

Determines an address's family, or verifies the one you claim it has.

**Signature:**

```typescript
export declare function getType(ip: string, type?: NetworkType): NetworkType;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| ip | string | the address to inspect |
| type | [NetworkType](https://imqueue.org/api/net/latest/net.networktype/) | _(Optional)_ the family you expect; omit to have it detected |


**Returns:**

[NetworkType](https://imqueue.org/api/net/latest/net.networktype/)

The family the address belongs to. When `type` was supplied and matches, that same value comes back.

## Exceptions

TypeError if `ip` is empty, if it contains neither `:` nor `.` so no family can be detected, if `type` is not a [NetworkType](https://imqueue.org/api/net/latest/net.networktype/), or if `type` disagrees with the address.

## Remarks

Detection is by punctuation only — a `:` means IPv6 and a `.` means IPv4, with `:` winning, which is what classifies the IPv4-mapped form `::ffff:1.2.3.4` as IPv6. It does not check that the address is well formed, so `getType('1.2.3.999')` returns `IPV4` quite happily; use [validate()](https://imqueue.org/api/net/latest/net.validate/) or [isValid()](https://imqueue.org/api/net/latest/net.isvalid/) for that.

