forked from seba/servefile
Fixes and additional methos for ip-gathering
This commit is contained in:
parent
929da24f4c
commit
be8ad72b31
25
servefile
25
servefile
|
@ -14,6 +14,7 @@ import os
|
||||||
import SocketServer
|
import SocketServer
|
||||||
import socket
|
import socket
|
||||||
from stat import ST_SIZE
|
from stat import ST_SIZE
|
||||||
|
from subprocess import Popen, PIPE
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class FileHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
class FileHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
|
@ -108,9 +109,29 @@ def main():
|
||||||
# print urls with local network adresses
|
# print urls with local network adresses
|
||||||
print "\nSome addresses this file will be available under:"
|
print "\nSome addresses this file will be available under:"
|
||||||
|
|
||||||
ips = commands.getoutput(r"/bin/ip addr|" + \
|
# ip and ifconfig sometimes are located in /sbin/
|
||||||
|
os.environ['PATH'] += ':/sbin:/usr/sbin'
|
||||||
|
proc = Popen(r"ip addr|" + \
|
||||||
"sed -n -e 's/.*inet6\? \([0-9.a-fA-F:]\+\)\/.*/\\1/ p'|" + \
|
"sed -n -e 's/.*inet6\? \([0-9.a-fA-F:]\+\)\/.*/\\1/ p'|" + \
|
||||||
"grep -v '^fe80\|^127.0.0.1\|^::1'")
|
"grep -v '^fe80\|^127.0.0.1\|^::1'", shell=True, stdout=PIPE)
|
||||||
|
if proc.wait() != 0:
|
||||||
|
# ip failed somehow, falling back to ifconfig
|
||||||
|
oldLang = os.environ.get("LC_ALL", None)
|
||||||
|
os.environ['LC_ALL'] = "C"
|
||||||
|
proc = Popen(r"ifconfig|" + \
|
||||||
|
"sed -n 's/.*inet6\? addr: \?\([0-9a-fA-F.:]*\).*/" + \
|
||||||
|
"\\1/p'|" + \
|
||||||
|
"grep -v '^fe80\|^127.0.0.1\|^::1'", \
|
||||||
|
shell=True, stdout=PIPE, stderr=PIPE)
|
||||||
|
if oldLang:
|
||||||
|
os.environ['LC_ALL'] = oldLang
|
||||||
|
else:
|
||||||
|
del(os.environ['LC_ALL'])
|
||||||
|
if proc.wait() != 0:
|
||||||
|
print "Error: Could not locate any ips for you."
|
||||||
|
proc = None
|
||||||
|
if proc:
|
||||||
|
ips = proc.stdout.read().strip()
|
||||||
for ip in ips.split("\n"):
|
for ip in ips.split("\n"):
|
||||||
if ip.find(":") >= 0:
|
if ip.find(":") >= 0:
|
||||||
# ipv6
|
# ipv6
|
||||||
|
|
Loading…
Reference in New Issue