Skip to content

Instantly share code, notes, and snippets.

@linxlunx
Created September 3, 2014 07:23
Show Gist options
  • Save linxlunx/17db9c07fc85d3670719 to your computer and use it in GitHub Desktop.
Save linxlunx/17db9c07fc85d3670719 to your computer and use it in GitHub Desktop.
Scanning Easy Transfer in Network
#!/usr/bin/env python
import argparse
import sys
import socket
import fcntl
import struct
import time
import multiprocessing
import urllib2
import re
import datetime
def unwrap_self_f(arg, **kwarg):
return GetEasy.scan_easy(*arg, **kwarg)
class GetEasy:
def __init__(self):
self.now_int = time.time()
def get_self_ip(self, device):
# get ip address code from activestate
# http://code.activestate.com/recipes/439094-get-the-ip-address-associated-with-a-network-inter/
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
my_ip = socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', device[:15])
)[20:24])
return my_ip
except:
return False
def scan_easy(self, host):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((host, 80))
if result == 0:
try:
get_page = urllib2.urlopen('http://%s' %host).read()
if re.search(r'Easy Transfer', get_page):
print 'Easy Transfer Detected in %s' %host
return host
except Exception, err:
pass
def run(self, threads, ip_range):
pool = multiprocessing.Pool(processes=int(threads))
hosts = []
for i in xrange(1,255):
hosts.append('%s.%d' %('.'.join(ip_range.split('.')[0:3]), i))
get_ips = pool.map(unwrap_self_f, zip([self]*len(hosts), hosts))
return get_ips
if __name__ == '__main__':
now_int = time.time()
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--interface', help='network interface')
parser.add_argument('-t', '--threads', help='total threads, if not specified, will use single thread')
args = parser.parse_args()
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
if not args.interface:
parser.print_help()
sys.exit(1)
if not args.threads:
threads = 1
else:
threads = args.threads
c = GetEasy()
ip_addr = c.get_self_ip(args.interface)
if not ip_addr:
print 'invalid interface'
sys.exit(1)
print 'scanning wifi area...'
Detected = c.run(threads, ip_addr)
scanned_time = time.time() - now_int
print '255 hosts scanned in %s' %(datetime.timedelta(seconds=scanned_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment