From: yomguy Date: Thu, 9 Oct 2008 13:58:43 +0000 (+0000) Subject: Add get_ip_address() X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=9b3e5e99642a3eb9a3b0fecbf885ad4698c95934;p=telecaster-cgi.git Add get_ip_address() --- 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