0

Get endpoint by MAC

by
Published today

Get a Cisco ISE endpoint by its MAC address.

Script cisco_ise Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 6 hours ago
1
//native
2

3
/**
4
 * Get endpoint by MAC
5
 * Get one endpoint by its MAC address (ISE uses the MAC as the endpoint name). Any separator or case is accepted, e.g. 11:22:33:44:55:66, 11-22-33-44-55-66 or 1122.3344.5566.
6
 */
7
export async function main(auth: RT.CiscoIse, mac: string) {
8
  // ISE stores MACs as AA:BB:CC:DD:EE:FF
9
  const hex = mac.replace(/[-:.\s]/g, "").toUpperCase()
10
  if (!/^[0-9A-F]{12}$/.test(hex))
11
    throw new Error(`Invalid MAC address: ${mac}`)
12
  const macAddress = hex.match(/../g)!.join(":")
13

14
  const base = new URL(auth.base_url)
15
  if (auth.ers_port) base.port = String(auth.ers_port)
16
  const url = new URL(
17
    `/ers/config/endpoint/name/${encodeURIComponent(macAddress)}`,
18
    base
19
  )
20

21
  const response = await fetch(url, {
22
    headers: {
23
      Authorization: `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
24
      Accept: "application/json",
25
    },
26
  })
27

28
  if (!response.ok) {
29
    throw new Error(`${response.status} ${await response.text()}`)
30
  }
31

32
  return await response.json()
33
}
34