DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • Script get local IP
  • 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
C++

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

Pipeline

Need assistance?

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