示例#1
0
def kpost(rsc, username, password, payload):
    ADDR = 'baas.kinvey.com'
    PORT = 80
    HEADER = {'Host': '%s' % ADDR, 'Authorization': auth(username, password)}

    con = Spin()
    data = post_data(rsc, data=json.loads(payload), header=HEADER)

    Client(con)
    con.connect_ex((ADDR, PORT))

    xmap(con, CONNECT, set_up_con, data)
    return con
示例#2
0
文件: basic.py 项目: mfferreira/uxreq
def connect(rsc, username, password):
    ADDR = 'baas.kinvey.com'
    PORT = 80
    HEADER = {'Host': '%s' % ADDR, 'Authorization': auth(username, password)}

    con = Spin()
    data = get(rsc, header=HEADER)

    Client(con)
    con.connect_ex((ADDR, PORT))

    xmap(con, CONNECT, set_up_con, data)
    xmap(con, CONNECT_ERR, lambda con, err: lose(con))

    return con
示例#3
0
文件: simple.py 项目: lowks/untwisted
def connect(addr, port, rsc):
    HEADER = {
        'Host': '%s' % addr,
        'User-Agent': "uxreq/1.0",
        'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
        'Connection': 'close',
    }

    con = Spin()
    data = get(rsc, header=HEADER)

    Client(con)
    con.connect_ex((addr, port))
    xmap(con, CONNECT, set_up_con, data)
    xmap(con, CONNECT_ERR, lambda con, err: lose(con))

    return con
示例#4
0
# Name: foo.py
# Description: This example connects to a local socket it sends
# a chunk of text and disconnects.

from untwisted.network import xmap, Spin, core
from untwisted.utils.stdio import Client, Stdin, CONNECT, DUMPED, lose
from socket import *


def set_up_con(con):
    # We install Stdin to be able of sending data.
    Stdin(con)
    # When everything is sent it just disconnects.
    xmap(con, DUMPED, lose)

    # Stdin installs dump method in con.
    # So, we can use it to send data.
    con.dump('Hello world\r\n')


sock = socket(AF_INET, SOCK_STREAM)
con = Spin(sock)
Client(con)
con.connect_ex(('localhost', 1234))
xmap(con, CONNECT, set_up_con)

core.gear.mainloop()
示例#5
0
""" Author: Jayrays
    Description: A simple port scan that verifies for listening sockets.
"""

from untwisted.network import *
from untwisted.utils.stdio import Client, lose, CONNECT, CONNECT_ERR
from socket import *
from sys import argv

script, ip, low, high = argv


def is_open(spin, port):
    print 'Port %s is open.' % port


for ind in range(int(low), int(high)):
    sock = socket(AF_INET, SOCK_STREAM)
    spin = Spin(sock)
    Client(spin)
    xmap(spin, CONNECT, is_open, ind)
    xmap(spin, CONNECT_ERR, lambda con, err: lose(con))
    xmap(spin, CONNECT, lose)
    spin.connect_ex((ip, ind))

core.gear.mainloop()
示例#6
0
def main():
    con = Spin()
    con.connect(('irc.freenode.org', 7000))
    Client(con)
    xmap(con, CONNECT, on_connect)