Exemplo n.º 1
0
def main(args=sys.argv[1:]):
    import ipmsg
    from ipmsg.config import settings
    import ipmsg.consts as c
    from optparse import OptionParser

    usage = '%prog [options] message ip[:port]'
    parser = OptionParser(usage=usage)
    parser.add_option("-p", "--port", type="int", dest="port", default=c.IPMSG_DEFAULT_PORT,
                      help="port", metavar="PORT")
    parser.add_option("-u", "--user", dest="user", default='',
                      help="user name")
    parser.add_option("-g", "--group", dest="group", default='',
                      help="group name")
    parser.add_option("-b", "--broadcast", action="store_true", dest="broadcast", default=False,
                      help="broadcast", metavar="")
    parser.add_option("-s", "--seal", action="store_true", dest="seal", default=False,
                      help="seal message", metavar="")

    (options, args) = parser.parse_args()

    settings['user_name'] = options.user
    settings['group_name'] = options.group

    # TODO: It seems that I didn't implemented the multicast part...
    if options.broadcast:
        pass

    if len(args) < 2:
        parser.print_help()
        sys.exit()

    try:
        nics = ipmsg.get_all_network_interface()
        if len(nics) == 0:
            print('No network avalible.')
            sys.exit()

        msg = args[0]
        addrs = []
        for x in args[1:]:
            addr = x.split(':')
            if len(addr) == 1:
                addr.append(options.port)
            else:
                addr[1] = int(addr[1])
            addrs.append(tuple(addr))
    except NotImplemented:
        parser.print_help()
        sys.exit()
    else:
        ipmsg.init(port=options.port)
        ipmsg.engine.start_server()
        for addr in addrs:
            ipmsg.send(addrs=[addr], msg=msg, encrypt=False, seal=options.seal)
        print(ipmsg.whatsnew())
        ipmsg.engine.stop_server()
        sys.exit()
Exemplo n.º 2
0
    def do_send(self):
        msg = self.dlg.txt_send.get_text()
        """
        if len(msg) == 0 and not self.attachments.get_all():
            return
        """

        seal = self.dlg.chk_seal.get_active()
        password = seal and self.dlg.chk_password.get_active()
        webshare = self.dlg.chk_webshare.get_active()

        selected = self.dlg.cl.get_selected_contacts()
        if len(selected) == 0:
            return
        else:
            ipmsg.send(selected, msg, self.attachments.get_all(), multicast=(len(selected) > 1), seal=seal, password=password, webshare=webshare)

        self.dlg.destroy()
        if self.recv_win:
            self.recv_win.destroy()
Exemplo n.º 3
0
Arquivo: cmdline.py Projeto: yws/ipmsg
def main(args=sys.argv[1:]):
    import ipmsg
    from ipmsg.config import settings
    import ipmsg.consts as c
    from optparse import OptionParser

    usage = '%prog [options] message ip[:port]'
    parser = OptionParser(usage=usage)
    parser.add_option("-p",
                      "--port",
                      type="int",
                      dest="port",
                      default=c.IPMSG_DEFAULT_PORT,
                      help="port",
                      metavar="PORT")
    parser.add_option("-u",
                      "--user",
                      dest="user",
                      default='',
                      help="user name")
    parser.add_option("-g",
                      "--group",
                      dest="group",
                      default='',
                      help="group name")
    parser.add_option("-b",
                      "--broadcast",
                      action="store_true",
                      dest="broadcast",
                      default=False,
                      help="broadcast",
                      metavar="")
    parser.add_option("-s",
                      "--seal",
                      action="store_true",
                      dest="seal",
                      default=False,
                      help="seal message",
                      metavar="")

    (options, args) = parser.parse_args()

    settings['user_name'] = options.user
    settings['group_name'] = options.group

    # TODO: It seems that I didn't implemented the multicast part...
    if options.broadcast:
        pass

    if len(args) < 2:
        parser.print_help()
        sys.exit()

    try:
        nics = ipmsg.get_all_network_interface()
        if len(nics) == 0:
            print('No network avalible.')
            sys.exit()

        msg = args[0]
        addrs = []
        for x in args[1:]:
            addr = x.split(':')
            if len(addr) == 1:
                addr.append(options.port)
            else:
                addr[1] = int(addr[1])
            addrs.append(tuple(addr))
    except NotImplemented:
        parser.print_help()
        sys.exit()
    else:
        ipmsg.init(port=options.port)
        ipmsg.engine.start_server()
        for addr in addrs:
            ipmsg.send(addrs=[addr], msg=msg, encrypt=False, seal=options.seal)
        print(ipmsg.whatsnew())
        ipmsg.engine.stop_server()
        sys.exit()