ich habe hier mal den code meiner Klasse angehängt nd wollte mal fragen warum der Interpreter die Kommandos :
newroute = {'NET':'224.0.0.0','MASK':'240.0.0.0','GATEWAY':'192.168.10.10'}
add = 'add'
route(newroute, add)
mit diesem Abschluss kommentiert :
<__main__.route instance at 0x00E94CB0>
Es wird alles ausgeführt, wie ich es will aber er sagt mir immer, an welche Speicherstelle er die Instanz hingeklebt hat.
Code: Alles auswählen
# -*- coding: cp1252 -*-
"""
Klasse zum Modifizieren der Routingtabelle unter Windows
zuletzt geändert : 13.10.2005
"""
from os import popen
class route:
def __init__(self, routingdict, action):
"""
Benötigt werden ein Dictonary mit den Routinginformationen zum löschen oder erstellen einer Route
und eine Variable mit dem Inhalt : add oder del
13.10.2005
"""
self.routingdict = routingdict
if action == "add":
self._route_add()
elif action == "del":
self._route_delete()
else:
raise IOError("attribute 'action' is not defined well")
def _routingdata_test(self):
"""
Überprüft das Dictonary auf folgende Mindestangaben :
z.B. newroute = {'NET':'192.168.0.0','MASK':'255.255.0.0','GATEWAY':'10.1.1.1'}
13.10.2005
"""
a, b, c = "NET","MASK","GATEWAY"
a1 = a in self.routingdict
b1 = b in self.routingdict
c1 = c in self.routingdict
if a1 and b1 and c1 == True:
return True
else:
return False
def _route_add(self):
"""
Testet das Eingansdictonary mit der Funktion "routingdata_test()" und legt eine neue Route in der Routingtabelle an
mögliche Keys im Dictionary : NET, MASK, GATEWAY, METRIC, INTERFACE ( mind. jedoch NET, MASK, GATEWAY )
13.10.2005
"""
#Testen der Eingangsdaten auf Vollständigkeit und Übernahme der Werte
test = self._routingdata_test()
if test == True:
NET = self.routingdict['NET']
MASK = self.routingdict['MASK']
GATEWAY = self.routingdict['GATEWAY']
if "METRIC" in self.routingdict:
METRIC = self.routingdict['METRIC']
else:
METRIC = ""
if "INTERFACE" in self.routingdict:
INTERFACE = self.routingdict['INTERFACE']
else:
INTERFACE = ""
else:
return False
#String für das Kommando an's Betriebssystem zusammenbasteln
command = 'route add ' + NET + ' mask ' + MASK + ' ' + GATEWAY +' metric ' + METRIC + ' if ' + INTERFACE
#Anlegen der Route
popen(command, 'w')
Vielen Dank für eure Tipps und bitte nicht weinen, wenn ihr den code seht. Ich bin immer noch am Üben und Verstehen, wenn es um OOP und Python geht
Gruß Gunnar