[Tutor] Tutor Digest, Vol 124, Issue 21

Jon Engle jon.engle at gmail.com
Tue Jun 10 12:55:08 CEST 2014


Thank you for taking the time to help me understand, here is what I am
trying to accomplish:

Client FW Server
-------------
1024 | Allow |       1024
1025 | Deny | 1025
1026       | Allow | 1026
65535  | .... | 65535

I am trying to test the outbound configuration of a firewall (treat it like
a black box) for purposes of validating current configurations. The client
side of this is pretty straightforward but the server side is where I run
into issues. I am trying to keep this as simple as possible as I am pretty
new to Python. One of the challenges I see is not having a communications
channel between the client and the server. In the example above what
happens when port 1025 is blocked outbound and the client never receives a
response from the server? How would I make the client and the server
synchronize ports? I considered timers but again I am trying to keep this
simple. So that is what lead me to the path of binding all the ports at
once so that the client doesn't have to care what the server did/did not
receive. In my case I felt that binding all the server ports at once,was
the simplest solution but I am certainly open to other/better ways. I am
currently using python 2.7.5





On Tue, Jun 10, 2014 at 6:00 AM, <tutor-request at python.org> wrote:

> Send Tutor mailing list submissions to
>         tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>         tutor-request at python.org
>
> You can reach the person managing the list at
>         tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>    1. Re: python sockets (Alan Gauld)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 10 Jun 2014 08:35:34 +0100
> From: Alan Gauld <alan.gauld at btinternet.com>
> To: tutor at python.org
> Subject: Re: [Tutor] python sockets
> Message-ID: <ln6cg7$5jn$1 at ger.gmane.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 10/06/14 00:33, Jon Engle wrote:
> > I am trying to open ports 1025-65535 with the following code
>
> Why would you want to do that?
> It sounds like a great way to cripple your PC as it runs 64000 threads
> monitoring each of those ports. And it assumes that nothing else is
> using those ports already... And if you did find something trying to
> connect, what port is the server going to allocate? You've already
> grabbed them all?
>
> Can you explain your rationale for trying to do this? Unless you are
> trying a brute force technique to prevent anything from connecting to
> your computer?
>
> > found online with small modifications). I am unable to "bind" anything
> > other than the one port which is selected as input. What am I missing
> > and how do I bind all the ports simultaneously?
>
> I think you are missing the basic concepts of server computing. You
> should never need to bind all the ports at once.
>
> However as to your code... its hard to critique because you lost the
> indentation - presumably through posting in HTML? Try using plain text
> for posting code.
>
> > #!/usr/bin/python           # This is server.py file
> > from socket import *      #import the socket library
> > import thread #import the thread library
> >
> > startingPort=input("\nPlease enter starting port: ")
> > startingPort=int(startingPort)
> >
> > def setup():
> ...
> > ## now we create a new socket object (serv)
> > ## see the python docs for more information on the socket types/flags
> > serv = socket( AF_INET,SOCK_STREAM)
> > serv.bind((ADDR))
> > serv.listen(5)    #5 is the maximum number of queued connections we'll
> allow
> >
> > serv = socket( AF_INET,SOCK_STREAM)
> > serv.bind((ADDR))
> > serv.listen(5)    #5 is the maximum number of queued connections we'll
> allow
>
>
> Why do you do it twice?
>
> > print 'listening...'
>
> Is this Python 2 or 3? Your input lines above suggest its Python 3 but
> this print line suggests its Python 2. Which are you using?
>
> > PORT=PORT+1
> > conn,addr = serv.accept() #accept the connection
> > print '...connected!'
> > conn.send('TEST')
> > conn.close()
>
> You normally put the listening code inside a loop, waiting for a
> connection, processing it and then going back to listen some more....
>
> > while startingPort<65535:
> > thread.start_new_thread(setup())
> > startingPort=startingPort+1
>
> Minor niggle, if you must do this use a for loop. Its tidier.
> As a minimum you need some error handling to deal with
> unsuccessful attempts to bind. And you need a better way
> of processing connections.
>
> But fundamentally, I suspect that whatever you are trying to
> do there is a better approach!
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> https://mail.python.org/mailman/listinfo/tutor
>
>
> ------------------------------
>
> End of Tutor Digest, Vol 124, Issue 21
> **************************************
>



-- 
Cheers,

   Jon S. Engle
   jon.engle at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140610/ee547b6d/attachment-0001.html>


More information about the Tutor mailing list