From 8c950fd1699e42f6d63958eb60a1d5ce02212ebc Mon Sep 17 00:00:00 2001 From: yomguy <> Date: Thu, 9 Oct 2008 13:58:43 +0000 Subject: [PATCH] Add get_ip_address() --- tools.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools.py b/tools.py index c928a2b..63340ad 100644 --- a/tools.py +++ b/tools.py @@ -28,6 +28,17 @@ import string import time from xmltodict import * from mutagen.oggvorbis import OggVorbis +import socket +import fcntl +import struct + +def get_ip_address(ifname): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + return socket.inet_ntoa(fcntl.ioctl( + s.fileno(), + 0x8915, # SIOCGIFADDR + struct.pack('256s', ifname[:15]) + )[20:24]) def get_lines(file): """Get lines from a file""" @@ -104,4 +115,4 @@ def str_to_bool(string): return string == 'true' def norm_string(string): - pass \ No newline at end of file + pass -- 2.39.5