title: How to fake IP for testing in python
body: <p>I have a service that I'm publishing with avahi that could run on different machines.</p>
  
  <p>And I have some code, that detecting and getting IP of that machines, and then starts using this service.</p>
  
  <p>I wan't to automate tests, so I need to somehow fake several machines so they would have different IP addresses when avahi resolves them.</p>
  
  <p>Is this possible?</p>
  
  <pre><code>class ReceiversManager(object):
  
      def __init__(self, name, on_message_callback):
          self.logger = logging.getLogger()
          self.logger.setLevel(logging.DEBUG)
          self.name = name
          self.on_message_callback = on_message_callback
          self.service_detector = AvahiServiceDetector(self.name, self.on_new_system)
          self.receivers = []
          self.addresses = []
          self.logger.setLevel(logging.DEBUG)
  
      def on_new_system(self, name, address, port):
          if not address in self.addresses:
              self.addresses.append(address)
              self.receivers.append(self.create_new_receiver(address, port))
  
      def create_new_receiver(self, address, port):
          self.logger.info('new address {}, new receiver created'.format(address))
          requester = ZmqReq(host='tcp://' + address, port=5559)
          id = self.create_id()
          reply = requester.execute(ArchiveCreator.CREATE_QUEUES_REQUEST + ' ' + id)
          recent_queue_name = ArchiveManager.create_queue_name(ArchiveManager.default_recent_queue_name, id)
          return DirectRabbitReceiver(host=address, queue_name=recent_queue_name,
                               start_immediately=True, on_receive_callback=self.on_message_callback)
  
      @staticmethod
      def create_id():
          return uuid.uuid5(uuid.NAMESPACE_DNS, ReceiversManager.get_baseboard_id() + ReceiversManager.get_disk_id()).hex
  
      @staticmethod
      def get_baseboard_id():
          info = dmidecode.QuerySection('baseboard')
          return info[info.keys()[1]]['data']['Serial Number']
  
      @staticmethod
      def get_disk_id():
          result = subprocess.check_output(['hdparm', '-I', '/dev/sda']).split()
          return result[result.index('Serial') + 2]
  
  class AvahiServicePublisher():
  
      def __init__(self):
          self.group = None
          bus = dbus.SystemBus()
          server = dbus.Interface(
              bus.get_object(
                  avahi.DBUS_NAME,
                  avahi.DBUS_PATH_SERVER),
              avahi.DBUS_INTERFACE_SERVER)
  
          self.group = dbus.Interface(
              bus.get_object(avahi.DBUS_NAME,
                             server.EntryGroupNew()),
              avahi.DBUS_INTERFACE_ENTRY_GROUP)
  
      def publish(self, name, port, stype="_http._tcp", domain="", host="", text=""):
          self.group.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0),
                                name, stype, domain, host,
                                dbus.UInt16(port), text)
  
          self.group.Commit()
  
      def unpublish(self):
          self.group.Reset()
  </code></pre>