DepthAI v2 has been superseded by DepthAI v3. You are viewing legacy documentation.
DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • Demo
  • Setup
  • Source code
  • Pipeline

Script get local IP

This example shows you how to get local IP (IP in the private network) of the device.

Demo

Command Line
1~/depthai-python/examples/Script$ python3 script_get_ip.py
2    Found device with name: 14442C1031425FD700-ma2480
3    Version: 0.0.15
4
5    Names of layers: ['fp16', 'uint8']
6    NNData size: 13
7    FP16 values: [1.0, 1.2001953125, 3.900390625, 5.5]
8    UINT8 values: [6, 9, 4, 2, 0]

Setup

Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai-python repository first and then run the script
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
For additional information, please follow the installation guide.

Source code

Python

Python
GitHub
1#!/usr/bin/env python3
2import depthai as dai
3
4# Start defining a pipeline
5pipeline = dai.Pipeline()
6
7# Script node
8script = pipeline.create(dai.node.Script)
9script.setProcessor(dai.ProcessorType.LEON_CSS)
10script.setScript("""
11import socket
12import fcntl
13import struct
14
15def get_ip_address(ifname):
16    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
17    return socket.inet_ntoa(fcntl.ioctl(
18        s.fileno(),
19        -1071617759,  # SIOCGIFADDR
20        struct.pack('256s', ifname[:15].encode())
21    )[20:24])
22
23ip = get_ip_address('re0')  # '192.168.0.110'
24node.warn(f'IP of the device: {ip}')
25node.io['end'].send(Buffer(32))
26""")
27
28xout = pipeline.create(dai.node.XLinkOut)
29xout.setStreamName('end')
30script.outputs['end'].link(xout.input)
31
32# Connect to device with pipeline
33with dai.Device(pipeline) as device:
34    device.getOutputQueue("end").get() # Wait for the "end" msg

C++

1#include <iostream>
2
3// Includes common necessary includes for development using depthai library
4#include "depthai/depthai.hpp"
5
6int main() {
7    using namespace std;
8
9    // Start defining a pipeline
10    dai::Pipeline pipeline;
11
12    // Script node
13    auto script = pipeline.create<dai::node::Script>();
14    script->setProcessor(dai::ProcessorType::LEON_CSS);
15    script->setScript(R"(
16    import socket
17    import fcntl
18    import struct
19
20    def get_ip_address(ifname):
21        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
22        return socket.inet_ntoa(fcntl.ioctl(
23            s.fileno(),
24            -1071617759,  # SIOCGIFADDR
25            struct.pack('256s', ifname[:15].encode())
26        )[20:24])
27
28    ip = get_ip_address('re0')  # '192.168.0.110'
29    node.warn(f'IP of the device: {ip}')
30    node.io['end'].send(Buffer(32))
31    )");
32
33    // XLinkOut
34    auto xout = pipeline.create<dai::node::XLinkOut>();
35    xout->setStreamName("end");
36    script->outputs["end"].link(xout->input);
37
38    // Connect to device with pipeline
39    dai::Device device(pipeline);
40    device.getOutputQueue("end")->get<dai::Buffer>();
41    return 0;
42}

Pipeline

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.