curl-and-python

Re: pyCurl : get IP address of the peer socket

From: ferrety ferrety <yferrety_at_gmail.com>
Date: Tue, 9 Sep 2008 11:54:15 +0200

Hi Mark,

Yep, "socket.fromfd" seems to do the trick. But as the doc says, it
duplicates the file descriptor:

http://python.about.com/od/pythonstandardlibrary/a/sock_doc3.htm
fromfd(...)
        fromfd(fd, family, type[, proto]) -> socket object
        Create a socket object from a duplicate of the given
        file descriptor.
        The remaining arguments are the same as for

So, is it the right way to do it?

Thanks

Regards
Ferret

On Tue, Sep 9, 2008 at 4:59 AM, Mark Eichin <eichin_at_gmail.com> wrote:
> Haven't tried it, but it looks like calling socket.fromfd on that
> integer should get you a pythonic-socket object wrapper that you can
> call getpeername on...
>
>
> ---------- Forwarded message ----------
> From: ferrety ferrety <yferrety_at_gmail.com>
> Date: Mon, Sep 8, 2008 at 6:52 PM
> Subject: pyCurl : get IP address of the peer socket
> To: curl-and-python_at_cool.haxx.se
>
>
> Hi List,
>
> I'd like to know how to get the "IP address" of the peer socket when
> downloding a URL with pycurl.
>
> After a bit of googling, I found this:
> sock = curl.getinfo(pycurl.LASTSOCKET);
>
> But it's seems to only return a socket file descriptor which is an integer.
> What I'd like to have is a full python "socket" object to use it like this:
>
> ipaddr, port = sock . getpeername()
>
> Advices please?
>
> Thanks in advance
>
> cheers
> Ferret
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
>
>
>
> --
> _Mark_ <eichin_at_thok.org> <eichin_at_gmail.com>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
>
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2008-09-09