def Ipv4MreqOption(level, option, doc): format = "4s4s" size = struct.calcsize(format) @option_error_decorator def getter(self): mcast, iface = struct.unpack(format, self._sock.getsockopt(level, option, size)) return _socket.inet_ntoa(mcast), _socket.inet_ntoa(iface) @option_error_decorator def setter(self, (mcast, iface)): raw = struct.pack(format, _socket.inet_aton(mcast), _socket.inet_aton(iface)) self._sock.setsockopt(level, option, raw)
def Ipv4MreqOption(level, option, doc): format = "4s4s" size = struct.calcsize(format) @option_error_decorator def getter(self): mcast, iface = struct.unpack( format, self._sock.getsockopt(level, option, size)) return _socket.inet_ntoa(mcast), _socket.inet_ntoa(iface) @option_error_decorator def setter(self, (mcast, iface)): raw = struct.pack(format, _socket.inet_aton(mcast), _socket.inet_aton(iface)) self._sock.setsockopt(level, option, raw)
def create_ip_option(option_number): option_name = DHCP_option.dhcp_attributes[option_number] if hasattr(config, option_name): return DHCP_option(option_number, 4, inet_aton(getattr(config, option_name))) else: return None
def collect_unique_per_ip(*dicts): result = {} for key in set.union(*(set(d) for d in dicts[0])): result[key] = sorted( set(sum((d.get(key, []) for d in dicts[0]), [])), key=lambda ip: struct.unpack("!L", inet_aton(ip))[0]) return result
def settings(request): servers = {} for language, version in SERVERS: servers[LANGUAGES[language] + '-' + VERSIONS[version]] =\ Server.objects.get(language=language, version=version) if request.method == 'POST': error = False for name in servers: server = servers[name] ip = request.POST.get(name + '-ip') port = request.POST.get(name + '-port') try: inet_aton(ip) except: messages.error( request, 'Invalid IP address for ' + name + ', changes discarded') error = True break try: port = int(port) except: messages.error( request, 'Invalid Port number for ' + name + ', changes discarded') error = True break if len(str(port)) not in [4, 5]: messages.error( request, 'Invalid Port number for ' + name + ', changes discarded') error = True break server.ip, server.port = ip, port server.save() if not error: request.session['settings_saved'] = True return redirect('index') server_names = sorted(servers.keys()) result = [] for name in server_names: result.append((name, servers[name].ip, servers[name].port)) return render_to_response('settings.html', RequestContext(request, {'result': result}))
def settings(request): servers = {} for language, version in SERVERS: servers[LANGUAGES[language] + '-' + VERSIONS[version]] =\ Server.objects.get(language=language, version=version) if request.method == 'POST': error = False for name in servers: server = servers[name] ip = request.POST.get(name + '-ip') port = request.POST.get(name + '-port') try: inet_aton(ip) except: messages.error(request, 'Invalid IP address for ' + name + ', changes discarded') error = True break try: port = int(port) except: messages.error(request, 'Invalid Port number for ' + name + ', changes discarded') error = True break if len(str(port)) not in [4, 5]: messages.error(request, 'Invalid Port number for ' + name + ', changes discarded') error = True break server.ip, server.port = ip, port server.save() if not error: request.session['settings_saved'] = True return redirect('index') server_names = sorted(servers.keys()) result = [] for name in server_names: result.append((name, servers[name].ip, servers[name].port)) return render_to_response('settings.html', RequestContext( request,{'result': result}))
def _ip2ulong(ip): '''点分十进制 -> unsigned long ''' return unpack('>L', _socket.inet_aton(ip))[0]
def _ip2ulong(ip): """点分十进制 -> unsigned long """ return unpack(">L", _socket.inet_aton(ip))[0]
def create_ip_option(option_number): option_name = DHCP_option.dhcp_attributes[option_number] if hasattr(config, option_name): return DHCP_option(option_number,4,inet_aton(getattr(config, option_name))) else: return None
def encode_nodes(node_list): return reduce( lambda x, y: x + y, map(lambda x: x[0] + inet_aton(x[1]) + pack('!H', x[2]), node_list)).decode('latin1')
def _ip2ulong(ip): return unpack('>L', _socket.inet_aton(ip))[0]