I new to Linux and currently having an issue when running a Python script on my second laptop (strange is that on my other machine the script runs without any issue)
Script that gets executed:
import socket
class DNSQuery:
def __init__(self, data):
self.data=data
self.dominio=''
tipo = (ord(data[2]) >> 3) & 15
if tipo == 0:
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'
packet+=self.data[12:]
packet+='\xc0\x0c'
packet+='\x00\x01\x00\x01\x00\x00\x00\x3c\x00\x04'
packet+=str.join('',map(lambda x: chr(int(x)), ip.split('.')))
return packet
if __name__ == '__main__':
ip='192.168.1.1'
print 'pyminiDwebconfNS:: 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 'Request: %s -> %s' % (p.dominio, ip)
except KeyboardInterrupt:
print 'Finalizando'
udps.close()
Following error occurs:
root@Sn3rpOs /m/r/B4A9-733B# python dns.py
pyminifakeDwebconfNS:: dom.query. 60 IN A 192.168.1.1
Traceback (most recent call last):
File "dns.py", line 33, in <module>
udps.bind(('',53))
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
I tried already to change the IP adress, but no luck, regardless which IP gets set the error occurs.
Then I checked with "netstat -an" to see if 192.168.1.1 is blocked, but unable to find anything
B4A9-733B# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address
Foreign Address State
tcp 0 0 127.0.0.1:5939 0.0.0.0:*
tcp 0 0 127.0.0.1:53 0.0.0.0:*
tcp 0 0 127.0.0.2:53 0.0.0.0:*
tcp 0 0 127.0.0.1:8118 0.0.0.0:*
tcp 0 0 127.0.0.1:9050 0.0.0.0:*
tcp 0 0 127.0.0.1:9051 0.0.0.0:*
tcp 0 1 192.168.179.135:57008 151.101.193.69:80
tcp 0 2824 192.168.179.135:57376 151.101.193.69:80
tcp 0 1 192.168.179.135:34152 151.101.65.69:80
tcp 0 644 192.168.179.135:50030 151.101.129.69:80
tcp 0 1 192.168.179.135:34154 151.101.65.69:80
tcp 0 0 127.0.0.1:9050 127.0.0.1:34242
tcp 0 0 192.168.179.135:54362 178.62.201.15:9090
tcp 0 1 192.168.179.135:57014 151.101.193.69:80
tcp6 0 0 ::1:8118 :::*
udp 0 0 127.0.0.1:47649 127.0.0.1:53
udp 0 2560 0.0.0.0:41994
udp 0 0 127.0.0.1:50619 127.0.0.1:53
udp 0 0 127.0.0.1:36289 127.0.0.1:53
My problem is that I don fully understand the reported error and what I could check/change to fix this. Hoping you guys can give some additional ideas to get this fixed.
Thanks Chimera