> For the complete documentation index, see [llms.txt](https://pcap.ardikars.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pcap.ardikars.com/getting-started/obtaining-the-device-list.md).

# Obtaining the device list

Note: There may be network devices that cannot be opened by the process calling Service.interfaces(), because, for example, that process does not have sufficient privileges to open them for capturing; if so, those devices will not appear on the list.

Docs[: libpcap](https://www.tcpdump.org/manpages/pcap.3pcap.html), [javadoc](https://javadoc.io/doc/com.ardikars.pcap/pcap-spi/latest/pcap/spi/Service.html).

{% tabs %}
{% tab title="Java" %}

```
public static void main(String[] _args) throws ErrorException {
  var service = Service.Creator.create("PcapService");
  Iterator<Interface> devices = service.interfaces().iterator();
  while (devices.hasNext()) {
    Interface device = devices.next();
    System.out.println("Name             : " + device.name());
    System.out.println("Description      : " + device.description());
    System.out.println("Flags            : " + device.flags());
    if (device.addresses() != null) {
      System.out.println("Addresses        : ");
      Iterator<Address> addresses = device.addresses().iterator();
      while (addresses.hasNext()) {
        Address address = addresses.next();
        System.out.println("\tAddress      : " + address.address());
        System.out.println("\tNetmask      : " + address.netmask());
        System.out.println("\tBroadcast    : " + address.broadcast());
        System.out.println("\tDestination  : " + address.destination());
      }
    }
    System.out.println();
  }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```
fun main() {
  val service = Service.Creator.create("PcapService")
  val devices: Iterator<Interface> = service.interfaces().iterator()
  while (devices.hasNext()) {
    val device = devices.next()
    println("Name             : " + device.name())
    println("Description      : " + device.description())
    println("Flags            : " + device.flags())
    if (device.addresses() != null) {
      println("Addresses        : ")
      val addresses: Iterator<Address> = device.addresses().iterator()
      while (addresses.hasNext()) {
        val address: Address = addresses.next()
        System.out.println("\tAddress      : " + address.address())
        System.out.println("\tNetmask      : " + address.netmask())
        System.out.println("\tBroadcast    : " + address.broadcast())
        System.out.println("\tDestination  : " + address.destination())
      }
    }
    println()
  }
}
```

{% endtab %}

{% tab title="Scala" %}

```
def main(args: Array[String]): Unit = {
  val service = Service.Creator.create("PcapService")
  val devices = service.interfaces.iterator
  while ( {
    devices.hasNext
  }) {
    val device = devices.next
    System.out.println("Name             : " + device.name)
    System.out.println("Description      : " + device.description)
    System.out.println("Flags            : " + device.flags)
    if (device.addresses != null) {
      System.out.println("Addresses        : ")
      val addresses = device.addresses.iterator
      while ( {
        addresses.hasNext
      }) {
        val address = addresses.next
        System.out.println("\tAddress      : " + address.address)
        System.out.println("\tNetmask      : " + address.netmask)
        System.out.println("\tBroadcast    : " + address.broadcast)
        System.out.println("\tDestination  : " + address.destination)
      }
    }
    System.out.println()
  }
}
```

{% endtab %}

{% tab title="Clojure" %}

```
(defn print_addresses [addresses]
  (println "Addresses        :")
  (while (.hasNext addresses)
    (def address (.next addresses))
    (println "\tAddreess      :" (.address address))
    (println "\tNetmask       :" (.netmask address))
    (println "\tBroadcast     :" (.broadcast address))
    (println "\tDestination   :" (.destination address))))

(defn -main
  [& args]
  (def service (. Service$Creator (create "PcapService")))
  (def devices (.iterator (.interfaces service)))
  (while (.hasNext devices)
    (def device (.next devices))
    (println "Name             :" (.name device))
    (println "Description      :" (.description device))
    (println "Flags            :" (.flags device))
    (if (some? (.addresses device))
      (print_addresses (.iterator (.addresses device))))))
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pcap.ardikars.com/getting-started/obtaining-the-device-list.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
