本文整理汇总了Python中models.Box.by_ip_address方法的典型用法代码示例。如果您正苦于以下问题:Python Box.by_ip_address方法的具体用法?Python Box.by_ip_address怎么用?Python Box.by_ip_address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Box
的用法示例。
在下文中一共展示了Box.by_ip_address方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_ipv6
# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_ip_address [as 别名]
def edit_ipv6(self):
''' Add ipv6 addresses to a box (sorta edits the box object) '''
form = Form(box_uuid="Select a box", ipv6="Please provide a list of IPv6 addresses")
if form.validate(self.request.arguments):
errors = []
box = Box.by_uuid(self.get_argument('box_uuid'))
if box is not None:
ips_string = self.get_argument('ipv6').replace('\n', ',').lower()
ips = filter(lambda char: char in "1234567890abcdef:,", ips_string).split(",")
for ip in filter(lambda ip: 0 < len(ip), ips):
try:
box = Box.by_ip_address(ip)
if box is None:
addr = IpAddress(box_id=box.id, v6=ip)
dbsession.add(addr)
else:
errors.append(
"%s has already been assigned to %s." % (ip, box.name,)
)
except ValueError:
errors.append(
"'%s' is not a valid IPv6 address" % str(ip[:39])
)
dbsession.flush()
else:
errors.append("Box does not exist")
self.render("admin/view/game_objects.html", errors=errors)
else:
self.render("admin/view/game_objects.html", errors=form.errors)
示例2: open
# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_ip_address [as 别名]
def open(self):
''' When we receive a new websocket connect '''
box = Box.by_ip_address(self.request.remote_ip)
if box is not None:
self.box = box
self.remote_ip = self.request.remote_ip
self.write_message("box ok")
else:
self.close()
示例3: open
# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_ip_address [as 别名]
def open(self, *args):
""" Steps 1 and 2; called when a new bot connects """
box = Box.by_ip_address(self.request.remote_ip)
self.remote_ip = self.request.remote_ip
if box is None and self.config.whitelist_box_ips:
logging.debug("Rejected bot from '%s' (not a box)" % self.request.remote_ip)
self.write_message({"opcode": "error", "message": "Invalid IP address."})
self.close()
else:
logging.debug("Interrogating bot on %s" % self.request.remote_ip)
self.write_message({"opcode": "interrogate", "xid": self.xid})
示例4: open
# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_ip_address [as 别名]
def open(self, *args):
''' Steps 1 and 2; called when a new bot connects '''
box = Box.by_ip_address(self.request.remote_ip)
self.remote_ip = self.request.remote_ip
if box is None and self.config.whitelist_box_ips:
logging.debug("Rejected bot from '%s' (not a box)" % self.request.remote_ip)
self.write_message({
'opcode': 'error',
'message': 'Invalid IP address.'
})
self.close()
else:
logging.debug("Interrogating bot on %s" % self.request.remote_ip)
self.write_message({'opcode': 'interrogate', 'xid': self.xid})
示例5: open
# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_ip_address [as 别名]
def open(self, *args):
''' When we receive a new websocket connect '''
box = Box.by_ip_address(self.request.remote_ip)
if box is not None:
self.box_uuid = box.uuid
self.box_name = box.name
self.remote_ip = self.request.remote_ip
self.write_message({
'opcode': 'get_user',
})
else:
logging.debug("Rejected bot from '%s' (not a box)" % self.request.remote_ip)
self.write_message({
'opcode': 'error',
'message': 'Invalid IP address.'
})
self.close()
示例6: get
# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_ip_address [as 别名]
def get(self, *args, **kwargs):
''' Registers a reporting service on a remote box '''
box = Box.by_ip_address(self.request.remote_ip)
if box != None:
try:
display_name = self.get_argument("handle")
user = User.by_display_name(display_name)
if user != None and not user.team.is_controlling(box):
user.give_control(box)
self.dbsession.add(user)
self.dbsession.flush()
self.notify(user, box)
self.write(unicode(user.team.listen_port))
else:
self.write("Invalid handle")
except:
self.write("Missing parameter")
else:
self.write("Invalid ip address")
self.finish()
示例7: get
# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_ip_address [as 别名]
def get(self, *args, **kwargs):
""" Registers a reporting service on a remote box """
box = Box.by_ip_address(self.request.remote_ip)
if box is not None:
try:
handle = self.get_argument("handle")
user = User.by_handle(handle)
if user is not None:
if not box in user.team.boxes:
user.team.boxes.append(box)
dbsession.add(user.team)
dbsession.flush()
self.write(unicode(user.team.listen_port))
else:
self.write("Invalid handle")
except:
self.write("Missing parameter")
else:
self.write("Invalid ip address")
self.finish()