]> git.parisson.com Git - telecaster-client.git/commitdiff
Add get_ip_address()
authoryomguy <>
Thu, 9 Oct 2008 13:58:43 +0000 (13:58 +0000)
committeryomguy <>
Thu, 9 Oct 2008 13:58:43 +0000 (13:58 +0000)
tools.py

index c928a2b0631539219c17b951b6ab41a8d6a9215a..63340adf7f00f740ffea1c3b92cd46bee317fb7a 100644 (file)
--- 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