Posts

Showing posts from 2018

Getting information about list of installed webcams programmatically using udev

If your writing an application in Linux where you dealing with low-level hardware details, using udev is a better choice rather than calling executable and reading the content in their STDOUT This is a small C code to get information about list of installed webcam programmatically using udev. This is written in C, this can be integrated with other languages such as Python, Java using a wrapper interface such as JNI(Java) or Python/C API   #include <libudev.h> #include <stdio.h> #include <stdlib.h> #include <locale.h> #include <unistd.h> int main(void) { struct udev * udev; struct udev_enumerate * enumerate; struct udev_list_entry * devices, * dev_list_entry; struct udev_device * dev; /* Create the udev object */ udev = udev_new(); if (!udev) { printf("Can't create udev\n"); exit(1); } /* Create a list of the devices in the 'video4linux' subsystem. */ enumerate = udev_enumerate_new(udev); udev_enu

DDNS with IPv6

My ISP provides /64 IPv6 block but it's a not a static block, so it's really annoying when I trying to  access my home server (yes, it's a raspberry pi) remotely as allocated IPv6 prefix block changes time to time. here's my solution for that Getting the current IP #!/bin/sh if [ -z "$1" ] then echo "usage : ./$0 <iface>" else ip -o -6 addr show $1 | sed -e 's/^.*inet6 \([^ ]\+\).*/\1/' | grep '/128' | awk -F '/' '{print $1}' fi I am using freedns.afraid.org as my DDNS provider (it's free), this is my script to run as a cron job to update latest IPv6 address #!/bin/sh ip6_addr=`./get-addr-dialog-bb.sh eth0` # last_ip6_addr=`cat ./.last_ip6_addr 2> /dev/null` host=`hostname -f` auth='<user>:<password>' # freedns.afraid.org credentails if [ "$ip6_addr" != "$last_ip6_addr" ] then curl -k "https://freedns.afraid.org/nic/update?hostname=$host&a