Permalink
Browse files

using alternative method to get host ip address

Signed-off-by: AutomatedTester <dburns@mozilla.com>
  • Loading branch information...
1 parent da035d9 commit 91ffb6369f0b423685c49d44c76f62abe387eb49 @lukeis lukeis committed with AutomatedTester Feb 28, 2014
Showing with 32 additions and 2 deletions.
  1. +2 −2 webdriver/base_test.py
  2. +30 −0 webdriver/network.py
View
@@ -2,11 +2,11 @@
import ConfigParser
import json
import os
-import socket
import unittest
from webserver import Httpd
from selenium import webdriver
+from network import get_lan_ip
class WebDriverBaseTest(unittest.TestCase):
@@ -37,7 +37,7 @@ def setUpClass(cls):
cls.driver = cls.driver_class(desired_capabilities=capabilities)
else:
cls.driver = cls.driver_class()
- cls.webserver = Httpd(host=socket.gethostbyname(socket.gethostname()))
+ cls.webserver = Httpd(host=get_lan_ip())
cls.webserver.start()
@classmethod
View
@@ -0,0 +1,30 @@
+# this comes from this stack overflow post:
+# http://stackoverflow.com/a/1947766/725944
+
+# module for getting the lan ip address of the computer
+
+import os
+import socket
+
+if os.name != "nt":
+ import fcntl
+ import struct
+ def get_interface_ip(ifname):
+ sckt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ return socket.inet_ntoa(fcntl.ioctl(
+ sckt.fileno(),
+ 0x8915, # SIOCGIFADDR
+ struct.pack('256s', ifname[:15])
+ )[20:24])
+
+def get_lan_ip():
+ ip = socket.gethostbyname(socket.gethostname())
+ if ip.startswith("127.") and os.name != "nt":
+ interfaces = ["eth0","eth1","eth2","wlan0","wlan1","wifi0","ath0","ath1","ppp0"]
+ for ifname in interfaces:
+ try:
+ ip = get_interface_ip(ifname)
+ break
+ except IOError:
+ pass
+ return ip

0 comments on commit 91ffb63

Please sign in to comment.