コード例 #1
0
ファイル: models.py プロジェクト: fenrrir/nimbus-opensource
 def clean(self):
     raw_iface = networkutils.get_interfaces()[0]
     if self.address == raw_iface.addr:
         return
     returncode, stdout = networkutils.ping(self.address, packets=1)
     if not returncode:
         raise ValidationError(u'Erro, existe outra máquina com o mesmo IP na rede.')
コード例 #2
0
def create_or_view_network_tool(request):

    if request.method == "POST":

        rtype = request.POST['type']
        ip = request.POST['ip']
        is_url = False

        try:
            try:
                validators.validate_ipv4_address(ip)  # ip format x.x.x.x
            except ValidationError, error:  # url format www.xxx.xxx
                value = ip
                if not '://' in value:
                    value = 'https://%s' % value
                urlvalidator = validators.URLValidator()
                urlvalidator(value)
                is_url = True

            if rtype == "ping":
                rcode, output = networkutils.ping(ip)
            elif rtype == "traceroute":
                rcode, output = networkutils.traceroute(ip)
            elif rtype == "nslookup":
                try:
                    if is_url:
                        output = networkutils.resolve_name(ip)
                    else:
                        output = networkutils.resolve_addr(ip)
                except (networkutils.HostAddrNotFound,
                        networkutils.HostNameNotFound), error:
                    output = "Não encontrado"
コード例 #3
0
def create_or_view_network_tool(request):


    if request.method  == "POST":
    
        rtype = request.POST['type']
        ip = request.POST['ip']
        is_url = False

        try:
            try:
                validators.validate_ipv4_address(ip) # ip format x.x.x.x
            except ValidationError, error: # url format www.xxx.xxx
                value = ip
                if not '://' in value:
                    value = 'https://%s' % value
                urlvalidator = validators.URLValidator()
                urlvalidator(value)
                is_url  = True

            if rtype == "ping":
                rcode, output = networkutils.ping(ip)
            elif rtype == "traceroute":
                rcode, output = networkutils.traceroute(ip)
            elif rtype == "nslookup":
                try:
                    if is_url:
                        output = networkutils.resolve_name(ip)
                    else:
                        output = networkutils.resolve_addr(ip)
                except (networkutils.HostAddrNotFound,
                         networkutils.HostNameNotFound), error:
                    output = "Não encontrado"
コード例 #4
0
 def clean(self):
     raw_iface = networkutils.get_interfaces()[0]
     if self.address == raw_iface.addr:
         return
     returncode, stdout = networkutils.ping(self.address, packets=1)
     if not returncode:
         raise ValidationError(u'Erro, existe outra máquina com o mesmo IP na rede.')