Exemple #1
0
    def gethostbyname(hostname):
        """:func:`socket.gethostbyname` implemented using :mod:`gevent.dns`.

        Differs in the following ways:

        * raises :class:`DNSError` (a subclass of :class:`socket.gaierror`) with dns error
          codes instead of standard socket error codes
        * does not support ``/etc/hosts`` but calls the original :func:`socket.gethostbyname`
          if *hostname* has no dots
        * does not iterate through all addresses, instead picks a random one each time
        """
        # TODO: this is supposed to iterate through all the addresses
        # could use a global dict(hostname, iter)
        # - fix these nasty hacks for localhost, ips, etc.
        if not isinstance(hostname, str) or '.' not in hostname:
            return _socket.gethostbyname(hostname)
        if _ip4_re.match(hostname):
            return hostname
        if hostname == _socket.gethostname():
            return _socket.gethostbyname(hostname)
        addrs = None
        try:
            _ttl, addrs = resolve_ipv4(hostname)
        except:
            _ttl, addrs = resolve_ipv6(hostname)
            return inet_ntop(AF_INET6, random.choice(addrs))
        else:
            return inet_ntop(AF_INET, random.choice(addrs))
Exemple #2
0
    def gethostbyname(hostname):
        """:func:`socket.gethostbyname` implemented using :mod:`gevent.dns`.

        Differs in the following ways:

        * raises :class:`DNSError` (a subclass of :class:`socket.gaierror`) with dns error
          codes instead of standard socket error codes
        * does not support ``/etc/hosts`` but calls the original :func:`socket.gethostbyname`
          if *hostname* has no dots
        * does not iterate through all addresses, instead picks a random one each time
        """
        # TODO: this is supposed to iterate through all the addresses
        # could use a global dict(hostname, iter)
        # - fix these nasty hacks for localhost, ips, etc.
        if not isinstance(hostname, str) or '.' not in hostname:
            return _socket.gethostbyname(hostname)
        if _ip4_re.match(hostname):
            return hostname
        if hostname == _socket.gethostname():
            return _socket.gethostbyname(hostname)
        addrs = None
        try:
            _ttl, addrs = resolve_ipv4(hostname)
        except:
            _ttl, addrs = resolve_ipv6(hostname)
            return inet_ntop(AF_INET6, random.choice(addrs))
        else:
            return inet_ntop(AF_INET, random.choice(addrs))
 def test_gethostbyname(self):
     '''Tests _socket.gethostbyname'''
     #sanity
     self.assertEqual(_socket.gethostbyname("localhost"), "127.0.0.1")
     self.assertEqual(_socket.gethostbyname("127.0.0.1"), "127.0.0.1")
     self.assertEqual(_socket.gethostbyname("<broadcast>"), "255.255.255.255")
     
     #negative
     self.assertRaises(_socket.gaierror, _socket.gethostbyname, "should never work")
Exemple #4
0
 def test_hostname_unicode(self):
     import _socket
     domain = u"испытание.pythontest.net"
     _socket.gethostbyname(domain)
     _socket.gethostbyname_ex(domain)
     _socket.getaddrinfo(domain, 0, _socket.AF_UNSPEC, _socket.SOCK_STREAM)
     s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM)
     s.connect((domain, 80))
     s.close()
     raises(TypeError, s.connect, (domain + '\x00', 80))
    def test_gethostbyname(self):
        '''Tests _socket.gethostbyname'''
        #sanity
        self.assertEqual(_socket.gethostbyname("localhost"), "127.0.0.1")
        self.assertEqual(_socket.gethostbyname("127.0.0.1"), "127.0.0.1")
        self.assertEqual(_socket.gethostbyname("<broadcast>"),
                         "255.255.255.255")

        #negative
        self.assertRaises(_socket.gaierror, _socket.gethostbyname,
                          "should never work")
 def ip(self) -> str:
     """
     Tries to give you the current ip of the host,
     if it could not be determined, the latest known ip is returned.
     """
     try:
         self.last_ip = gethostbyname(self.host)
     except TimeoutError:
         pass
     return self.last_ip
Exemple #7
0
def resolve(hostname, port=False):
    """
    Resolves hostname to IP address.
    IPv6 addresses get mapped to IPv6 if a port isn't supplied
    returns str(IP_address)
    """
    if port:
        return _socket.getaddrinfo(hostname, port)[0][4][0]
    else:
        return _socket.gethostbyname(hostname)
Exemple #8
0
    def __init__(self, host, port):
        """Create target instance using given host and port.

        :param host: IP address or FQDN of host
        :param port: port number
        :return: Target instance
        """
        parts = host.split(':')

        if match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", parts[0]):
            self.ip = parts[0]
        else:
            self.ip = gethostbyname(parts[0])

        self.port = int(parts[1]) if len(parts) == 2 else port
Exemple #9
0
def bindSocket(s, BindPort, local_ip):
    try:
        s.bind(('', BindPort))
        get_date_string()
        if local_ip != '':
            print("server:  + $local_ip + $BindPort")
        else:
            print("server:" + str(gethostbyname(gethostname())) +
                  str(BindPort))
    except Exception as e:
        print(e)
        get_date_string()
        print("ERROR: nie mozna zabindowac portu %s, wybierz inny BindPort")
        s.close()
        sys.exit()
Exemple #10
0
def portScan(tgtHost, tgtPorts):
    try:
        tgtIP = gethostbyname(tgtHost)
    except:
        print ("[-] Cannot resovle '%s' : Unknown host"%tgtHost)
        return
    try:
        tgtName = gethostbyaddr(tgtIP)
        print ("\n[+] Scan Result for: " + tgtName[0])
    except:
        print ("\n[+] Scan Result for: " + tgtIP)
    setdefaulttimeout(1)
    for tgtPort in tgtPorts:
#         print ("Scanning Port " + tgtPort)
        t = Thread(target=nmapScan, args=(tgtHost, tgtPort))
        t.start()
Exemple #11
0
def portScan(tgtHost, tgtPorts):
    try:
        tgtIP = gethostbyname(tgtHost)
    except:
        print("[-] Cannot resovle '%s' : Unknown host" % tgtHost)
        return
    try:
        tgtName = gethostbyaddr(tgtIP)
        print("\n[+] Scan Result for: " + tgtName[0])
    except:
        print("\n[+] Scan Result for: " + tgtIP)
    setdefaulttimeout(1)
    for tgtPort in tgtPorts:
        #         print ("Scanning Port " + tgtPort)
        t = Thread(target=nmapScan, args=(tgtHost, tgtPort))
        t.start()
Exemple #12
0
    def __init__(self, domain=None, ip=None):
        if domain is None and ip is None:
            raise Exception('TODO: error')

        self.ip = ip
        if ip is None:
            self.ip = gethostbyname(domain)

        self.domain = domain
        if self.domain is None:
            self.domain = self.ip_reverse_find_domain

        self.__lookup = None
        self.__sub_domain = None

        self._certificates = certificates.CensysCertificates(self.UID, self.SECRET)
Exemple #13
0
    def setup_notifier(self):
        parser = self._get_parser()

        port = 8100
        elem = parser.get_elements('port')
        if elem is not None:
            try:
                port = int(elem[0].text.strip())
            except ValueError:
                pass

        self.notifier.port = port
        host = gethostbyname(gethostname())
        self.url = '{}:{}'.format(host, port)
        #add a config request handler
        self.notifier.add_request_handler('config', self._handle_config)
Exemple #14
0
    def setup_notifier(self):
        parser = self._get_parser()

        port = 8100
        elem = parser.get_elements("port")
        if elem is not None:
            try:
                port = int(elem[0].text.strip())
            except ValueError:
                pass

        self.notifier.port = port
        host = gethostbyname(gethostname())
        self.url = "{}:{}".format(host, port)
        # add a config request handler
        self.notifier.add_request_handler("config", self._handle_config)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

SECRET_KEY = "6e2bmahu38vuzy0fd2xw*jz32*9tva_lp=$c!^v6pu)-4qd4k7"

EXPOSED_DOMAIN = f'@= project_name =@.{os.getenv("ENVIRONMENT_DOMAIN", "")}'

ALLOWED_HOSTS = [
    "localhost",
    "127.0.0.1",
    "@= project_name =@",
    "@= project_name [email protected]",
    gethostname(),
    gethostbyname(gethostname()),
    EXPOSED_DOMAIN,
]

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    "commands",
    "django_prometheus",
    "events",
import _socket as socket
import struct
import sys
import re

HOST = socket.gethostbyname(socket.gethostname())
PORT = 0


class TCPSniffer:
    def __init__(self):
        self.s = self.connect()

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)

    def connect(self):
        s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
        s.bind((HOST, 0))

        s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

        s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)

        return s

    def receive_data(self):
        try:
Exemple #17
0
 def url(self):
     host = gethostbyname(gethostname())
     return '{}:{}'.format(host, self.port)
Line 9: NBC Contamination


Further ideas;

Dial up internet- track the ip address to find the geo location 

"""

import datetime
import _socket


# s = socket.socket(socket.AF_INET, socket.sock_DGRAM)
# s.connect("8.8.8.8",80)
IP = _socket.gethostbyname(_socket.gethostname())

class medivac():
    def __init__(self):
        self.date= datetime.datetime.now()
        self.ip_address =IP

    def __repr__(self):
        raise NotImplementedError


class ninelines(medivac):
    """
            This initializes the 9 lines of medivac
            :param line_1: Location of the pick-up site.
            :param line_2: Radio frequency, call sign, and suffix.
Exemple #19
0
 def url(self):
     host = gethostbyname(gethostname())
     return '{}:{}'.format(host, self.port)
Exemple #20
0
def post_query_view(request):
    advertisement_images_list = []
    verticle_ads_list = []
    advertisement_images = AdvertisementDetails.objects.all()
    for a in advertisement_images:
        ads_image = str(a.Ads_images)
        if a.ads_category == 'Bottom Image Banner':
            advertisement_images_list.append(ads_image)
        else:
            verticle_ads_list.append(ads_image)


    all_menu_category = Menu_Category.objects.all()
    all_sub_category = Sub_Category.objects.all()
    all_region = Region.objects.all()
    form = CaptchaForm()
    menu_category_details = Menu_Category.objects.filter(menu_category="Arbeit")
    for m in menu_category_details:
        menu_id = m.id
        sub_category_details = Sub_Category.objects.filter(menu_category_id = menu_id)
    if request.POST:
        menu_category = request.POST.get('menu_category').encode('utf-8')
        sub_category = request.POST.get('sub_category')
        select_region = request.POST.get('region').encode('utf-8')
        if request.POST.get('title'):
            title = request.POST.get('title').encode('utf-8')
            if request.POST.get('description'):
                description = request.POST.get('description').encode('utf-8')
                agree = request.POST.get('agree')
                if agree == "on":
                    contact = request.POST.get('contact').encode('utf-8')
                    name = request.POST.get('name').encode('utf-8')
                    tel_no = request.POST.get('tel').encode('utf-8')
                    company_name = request.POST.get('company_name').encode('utf-8')
                    set_timer = request.POST.get('set_timer').encode('utf-8')
                    post_time = datetime.datetime.now()
                    try:

                        post_image = request.FILES['post_images'].encode('utf-8')

                    except MultiValueDictKeyError:
                        post_image = False

                    challenge_field = request.POST['recaptcha_challenge_field']
                    if request.POST['recaptcha_response_field']:
                        response_field = request.POST['recaptcha_response_field']
                        client_ip_address = gethostbyname(gethostname())
                        d = confirm(client_ip_address,
                                        recaptcha_challenge_field=challenge_field,
                                        recaptcha_response_field=response_field)
                        if d:
                            add_post_details_object = Add_Post_Details.objects.create(menu_category=menu_category,sub_category=sub_category,title=title,description=description,\
                                        contact=contact,name=name, tel=tel_no,company_name=company_name, set_timer= set_timer, post_time=post_time, region=select_region)
                            add_post_details_object.save()
                            try:
                                if request.POST.get("nof_image_field"):
                                    nof_image_field = int(request.POST.get("nof_image_field"))
                                    for i in range(nof_image_field):
                                        post_image = request.FILES[str(i+1)]
                                        Post_Images.objects.create(post=add_post_details_object,post_image=post_image)

                                else:
                                    post_image = request.FILES["1"]
                                    Post_Images.objects.create(post=add_post_details_object,post_image=post_image)
                            except MultiValueDictKeyError:
                                post_image = False
                        else:
                            error = "Captcha not match!"
                            return render(request, 'post-query.html', {'form':form,'error': error, 'selected_data':request.POST,'all_menu_category':all_menu_category,'all_sub_category':all_sub_category, 'all_region':all_region,'menu_category':'Arbeit','sub_category_details':sub_category_details,'ads_image':advertisement_images_list,'verticle_ads_list':verticle_ads_list})
                    else:
                        error = "Plz Enter Captcha!"
                        return render(request, 'post-query.html', {'form':form,'error': error, 'selected_data':request.POST,'all_menu_category':all_menu_category,'all_sub_category':all_sub_category, 'all_region':all_region,'menu_category':'Arbeit','sub_category_details':sub_category_details,'ads_image':advertisement_images_list,'verticle_ads_list':verticle_ads_list})
                else:
                    error = "Plz agree to our Terms & condition and Privacy Policy!"
                    return render(request, 'post-query.html', {'form':form,'error': error, 'selected_data':request.POST,'all_menu_category':all_menu_category,'all_sub_category':all_sub_category, 'all_region':all_region,'menu_category':'Arbeit','sub_category_details':sub_category_details,'ads_image':advertisement_images_list,'verticle_ads_list':verticle_ads_list})

            else:
                error = "Plz Enter Description!"
                return render(request, 'post-query.html', {'form':form,'error': error, 'selected_data':request.POST,'all_menu_category':all_menu_category,'all_sub_category':all_sub_category, 'all_region':all_region,'menu_category':'Arbeit','sub_category_details':sub_category_details,'ads_image':advertisement_images_list,'verticle_ads_list':verticle_ads_list})

        else:
            error = "Plz Enter Title Name!"
            return render(request, 'post-query.html', {'form':form,'error': error, 'selected_data':request.POST,'all_menu_category':all_menu_category,'all_sub_category':all_sub_category, 'all_region':all_region,'menu_category':'Arbeit','sub_category_details':sub_category_details,'ads_image':advertisement_images_list,'verticle_ads_list':verticle_ads_list})
        return HttpResponseRedirect('/index/')
    else:
        return render(request, 'post-query.html', {'form':form,'all_menu_category':all_menu_category,'all_sub_category':all_sub_category,'all_region':all_region, 'sub_category_details':sub_category_details,'ads_image':advertisement_images_list,'verticle_ads_list':verticle_ads_list})
Exemple #21
0
def main_context():
    """ Include some basic assets in the startup page """
    today = datetime.today()
    current_ip = gethostbyname(gethostname())
    return locals()
Exemple #22
0
        portmap_success, upnp = (None, None)

    if not portmap_success:
       log("Couldn't forward port at the gateway.", "warning")
       log("Internet hosts will not be able to initiate connections to us.", "warning")

    try:
        app.routes   = dht.Routers()
        sys.exitfunc = app.routes.leave_networks

        if portmap_success and  options.address == '0.0.0.0':
            addr = upnp.externalipaddress()
        elif options and options.address != '0.0.0.0':
            addr = options.address
        else:
            addr = _socket.gethostbyname(_socket.gethostname())

        # Get on the default network
        router = dht.RoutingTable(
                addr,
                options.port,
                app.key.publickey().exportKey(),
                httpd,
                nodes=app.bootstrap_nodes,
                network=app.default_network,
                autoreplicate=options.autoreplicate
        )
        app.routes.append(router)

        # Reload prior networks
        for network in Network.query.all():