This article illustrates how to create a WiFi Web application server to distribute local area contents for smartphones

WiFi adapter setup

/etc/network/interfaces:  Code position: CD://Debian/playground/python/wab/interfaces

auto lo
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet dhcp
hwaddress ether 00:01:04:1b:2C:1F

auto wlan0
iface wlan0 inet static
address 192.168.2.1
netmask 255.255.255.0

WiFi Access point with Hostapd

Install hostapd package:

debarm:~# apt-get install hostapd

Create a configuration file with the following contents:

  • hostapd.conf Code position: CD://Debian/playground/python/wab/hostapd.conf
    #change wlan0 to your wireless device
    interface=wlan0
    driver=nl80211
    ssid=AriaG25
    channel=1

Launch Hostapd:

debarm:~# hostapd hostapd.conf &

DHCP Server

debarm:~# apt-get install isc-dhcp-server

Edit the /etc/default/isc-dhcp-server file and set the port to bind:

INTERFACES="wlan0"

Now configure our DHCP server is to specify subnetworks in its configuration file etc/dhcp/dhcpd.conf.

Here is the example of the file:

  • dhcpd.conf: Code position: CD://Debian/playground/python/wab/dhcpd.conf
    ddns-update-style none;
    
    option domain-name "ariag25.org";
    option domain-name-servers 192.168.2.1;
    
    default-lease-time 600;
    max-lease-time 7200;
    
    authoritative;
    
    log-facility local7;
    
    subnet 192.168.2.0 netmask 255.255.255.0 {
    	range 192.168.2.50 192.168.2.100;
    	option routers 192.168.2.1;
    }
    

When the configuration is done, restart the dhcp server:

debarm:~# /etc/init.d/isc-dhcp-server restart

If the server is complaining about something, see the "/var/log/syslog" for more details.

FakeDNS

  • fakedns.py: Code position: CD://Debian/playground/python/wab/fakedns.py
    import socket
    
    class DNSQuery:
      def __init__(self, data):
        self.data=data
        self.dominio=''
    
        tipo = (ord(data[2]) >> 3) & 15   # Opcode bits
        if tipo == 0:                     # Standard query
          ini=12
          lon=ord(data[ini])
          while lon != 0:
            self.dominio+=data[ini+1:ini+lon+1]+'.'
            ini+=lon+1
            lon=ord(data[ini])
    
      def respuesta(self, ip):
        packet=''
        if self.dominio:
          packet+=self.data[:2] + "\x81\x80"
          packet+=self.data[4:6] + self.data[4:6] + '\x00\x00\x00\x00'   # Questions and Answers Counts
          packet+=self.data[12:]                                         # Original Domain Name Question
          packet+='\xc0\x0c'                                             # Pointer to domain name
          packet+='\x00\x01\x00\x01\x00\x00\x00\x3c\x00\x04'             # Response type, ttl and resource data length -> 4 bytes
          packet+=str.join('',map(lambda x: chr(int(x)), ip.split('.'))) # 4bytes of IP
        return packet
    
    if __name__ == '__main__':
      #qui devi mettere l'IP della FOX
      ip='192.168.2.1'
    
      print 'pyminifakeDNS:: dom.query. 60 IN A %s' % ip
      
      udps = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
      udps.bind(('',53))
      
      try:
        while 1:
          data, addr = udps.recvfrom(1024)
          p=DNSQuery(data)
          udps.sendto(p.respuesta(ip), addr)
          print 'Risposta: %s -> %s' % (p.dominio, ip)
      except KeyboardInterrupt:
        print 'Fine'
        udps.close()
        

Install non-free Atheros firmware

Add a "non-free" component to /etc/apt/sources.list, for example:

deb http://http.debian.net/debian/ wheezy main contrib non-free

Update the list of available packages and install the firmware-atheros package:

# apt-get update && apt-get install firmware-atheros

Related links

Documentation Terms of Use
The Acme Systems srl provides this Debian system development and user manual.
The origin of these doc came from the website: http://www.acmesystems.it
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Creative Commons License


Market Mail : market@armdevs.com
Support Mail: support@armdevs.com Sales Phone: +86-755-29638421


CoreWind Online Chat>
Work time: 09:00-18:00
Copyright @ 2014 to 2020 - CoreWind Tech.