473,382 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Python Sockets Help

I need your expertise with a sockets question.

Let me preface this by saying I don't have much experience with
sockets in general so this question may be simple.

I am playing with the mini dns server from a script I found online:
http://aspn.activestate.com/ASPN/Coo...1264/index_txt

All I want to do is edit this script so that it records the IP
address. I've seen other examples use the accept() object which
returns the data and the IP address it is receiving the data from. I
can't use that in this case but I'm wondering if someone could show me
how.

Here is the socket part of the script:

if __name__ == '__main__':
ip='192.168.1.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 'Respuesta: %s -%s' % (p.dominio, ip)
except KeyboardInterrupt:
print 'Finalizando'
udps.close()

Thanks to everyone in advance!
~Mark
Mar 10 '08 #1
2 1584
On Mon, Mar 10, 2008 at 6:58 PM, Mark M Manning <ma**********@gmail.comwrote:
I need your expertise with a sockets question.

Let me preface this by saying I don't have much experience with
sockets in general so this question may be simple.

I would suggest taking a quick look at this tutorial.
http://ilab.cs.byu.edu/python/

Especially this:
http://ilab.cs.byu.edu/python/socket/echoserver.html
Mar 10 '08 #2
On 10 Mar, 23:58, Mark M Manning <mark.mann...@gmail.comwrote:
I need your expertise with a sockets question.

Let me preface this by saying I don't have much experience with
sockets in general so this question may be simple.

I am playing with the mini dns server from a script I found online:http://aspn.activestate.com/ASPN/Coo...1264/index_txt

All I want to do is edit this script so that it records the IP
address. *I've seen other examples use the accept() object which
returns the data and the IP address it is receiving the data from. *I
can't use that in this case but I'm wondering if someone could show me
how.

Here is the socket part of the script:

if __name__ == '__main__':
* ip='192.168.1.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 'Respuesta: %s -%s' % (p.dominio, ip)
* except KeyboardInterrupt:
* * print 'Finalizando'
* * udps.close()

Thanks to everyone in advance!
~Mark
You already have the address of the sender, is in the 'addr' variable,
as returned by udps.recvfrom.
Change the print statement in sometinmh like:
print 'Respuesta (%s): %s -%s' % ( addr, p.dominio, ip)
and you will see the sender address in dotted notation printed inside
the ().

Ciao
-------
FB
Mar 11 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Zunbeltz Izaola | last post by:
Hi! I want to port a small socket aplication (in C) to Python. The server is writen in C, and it expected to recibe and C struct like this struct tag_instruccion { unsigned int Handle ...
4
by: linuxpld | last post by:
Hello I`m writing a program (server in future) in python. I would like to write it in such a way that I will be able to write gui in any language and connect to my python program and use...
15
by: diffuser78 | last post by:
I am a newbie in python. I want to learn and implement a small networking concept. Please help me. Every help is appreciated. I have one Linux Box and one Windows PC. I want to have a daemon...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 398 open ( +5) / 3334 closed (+19) / 3732 total (+24) Bugs : 904 open ( -4) / 6011 closed (+36) / 6915 total (+32) RFE : 222 open...
1
by: William Connery | last post by:
Hi, I have a small python program with e-mail capabilities that I have pieced together from code snippets found on the internet. The program uses the smtplib module to successfully send an...
4
by: Mark Dufour | last post by:
Hi all, I have just released Shed Skin 0.0.23. It doesn't contain the type inference scalability improvements I was working on, but it does have quite a few bug fixes and minor feature...
0
by: wesley chun | last post by:
Need to get up-to-speed with Python as quickly as possible? Come join me, Wesley Chun, author of Prentice-Hall's bestseller "Core Python Programming," for another comprehensive intro course plus a...
0
by: wesley chun | last post by:
*** FINAL REMINDER also, the course begins on monday immediately following the *free* CodeCamp conference http://siliconvalley-codecamp.com (click Program => Sessions to see all the talks)... 5...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.