Commit 23c477c1 authored by Michael König's avatar Michael König

support for ipv6 (and 4) + parse hostnames

parent 1b7d1561
......@@ -28,14 +28,39 @@ class SocketInput(InputBase):
self.socketUp = False
self.__stopped = threading.Event()
ip, separator, port = self.options.logServer.rpartition(':')
if(':' not in self.options.logServer or port is ''):
self.logServerPort = DEFAULT_SOCKETSERVER_PORT
self.logServerIp = ip_address(socket.gethostbyname(self.options.logServer.strip("[]")))
if(":" not in self.options.logServer): # only ipv4-address or hostname w/o port given
ip = self.options.logServer
port = DEFAULT_SOCKETSERVER_PORT
elif(self.options.logServer.count(":") > 1): # ipv6-address given
try:
ip = ip_address(self.options.logServer)
except ValueError:
try:
ip, separator, port = self.options.logServer.rpartition(':')
self.logServerIp = ip_address(ip)
except ValueError:
print("Fatal error (Log-Server location malformatted)... should not have done this...")
else:
port = DEFAULT_SOCKETSERVER_PORT
else: # ipv4-address w/ port given
ip, separator, port = self.options.logServer.rpartition(':')
if(port is ''):
port = DEFAULT_SOCKETSERVER_PORT
try:
self.logServerIp = ip_address(ip)
except ValueError:
self.logServerIp = ip_address(socket.gethostbyname(ip.strip("[]")))
else:
self.logServerPort = int(port)
self.logServerIp = ip_address(socket.gethostbyname(ip.strip("[]")))
pass
self.logServerPort = int(port)
self.dst = str(self.logServerIp) + ":" + str(self.logServerPort)
if(self.options.debug):
print(str(self.dst))
def startupCheck(self):
pass
......@@ -52,7 +77,10 @@ class SocketInput(InputBase):
def createSocket(self):
try:
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if(ip_address(self.logServerIp).version is 4):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
else:
self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
except socket.error:
print("Failed to create socket")
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment