Controlling the IP sabnzbd pulls newsgroup data with.

Get help with all aspects of SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
lord_rahlly
Newbie
Newbie
Posts: 8
Joined: December 22nd, 2013, 11:19 pm

Controlling the IP sabnzbd pulls newsgroup data with.

Post by lord_rahlly »

Hello,

I run sabnzbd on Fedora 19. On my machine I have each service, couch, sickbeard, sabnzbd, plex, etc on their own virtual IP. It simplifies some things but complicates others at times, like now. I have started using a reporting app to monitor bandwidth consumption on my LAN. The problem is sabnzbd, despite being set to use the ip 192.169.0.47 which it answers on just fine, when downloading from newsgroups it appears to be using the first or lowest available IP of 192.168.0.45. This typically happens when an app is just picking 0.0.0.0. Is there any way in sab to change this activity so that the IP it downloads from is the same as the host setting in the ini file?

Thanks!
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Controlling the IP sabnzbd pulls newsgroup data with.

Post by sander »

I've been thinking about the same, but in my case for source IPv6 addressess: with IPv6 you often automatically have more than 1 IPv6 address, and it can useful to select which one to use for outgoing sesssions.

I'm quite sure you can NOT set that as an option in the SABnzbd. And I'm quite sure that is a wise thing: how could you safely instruct SABnzbd to use which source IP address without causing possible problems, especially for other users? ::)

If you want to program yourself: I think what you want is called "bind before connect".

Snippet from https://idea.popcount.org/2014-04-03-bi ... e-connect/

Code: Select all

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Let the source address be 192.168.1.21:1234
s.bind(("192.168.1.21", 1234))
s.connect(("www.google.com", 80))
I tried it with IPv6 source address, and it seems to work:

Code: Select all

import socket
#s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
# Let the source address be 192.168.1.21:1234
#s.bind(("192.168.1.21", 1234))
s.bind(('2001:4aa8:ff00:0:d84b:bc94:91d:d767', 5555))
s.connect(("www.google.com", 80))
print s.getsockname()[0]
print s.getsockname()
I don't know how SABnzbd does it's outgoing NNTP connections. If it uses a non-SAB library for that (and thus no bare connect and bind within the SAB code), it's probably harder to achieve what you want.

HTH
lord_rahlly
Newbie
Newbie
Posts: 8
Joined: December 22nd, 2013, 11:19 pm

Re: Controlling the IP sabnzbd pulls newsgroup data with.

Post by lord_rahlly »

Thanks sander, that looks like the trick. If I set a line in the newswrapper.py to

sock.bind("192.168.0.47", 0)

In the con module it works. Have a witch of a time getting that IP from the ini file. If I do;
logging.error(sabnzbd.cfg.email_server())

I can pull the IP for the email server while in the above file. But, if I do;

logging.error(sabnzbd.cfg.host())

The process dies and says;
Exception in thread Thread-25:
Traceback (most recent call last):
File "/usr/lib64/python2.7/threading.py", line 811, in __bootstrap_inner
self.run()
File "/usr/lib64/python2.7/threading.py", line 764, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/share/SABnzbd/sabnzbd/newswrapper.py", line 120, in con
logging.error(sabnzbd.cfg.host())
AttributeError: 'module' object has no attribute 'host'
Python is not one of the languages I normally work in but this is frustrating as heck. These two items are in the same section of the ini file.
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Controlling the IP sabnzbd pulls newsgroup data with.

Post by sander »

Ah ... so you want to use the IP address already specificied in sabnzbd.ini as listening host, also as the outgoing IP address? Clever! Less risk on mistakes.

Use this:

sabnzbd.cfg.cherryhost()


EDIT:

If you proceed, here's an advice:

convert your code to:

Code: Select all

try:
    sock.bind("192.168.0.47", 0) 
except:
    pass
to catch situations where host = 127.0.0.1 or otherwise unusable for a bind

HTH
lord_rahlly
Newbie
Newbie
Posts: 8
Joined: December 22nd, 2013, 11:19 pm

Re: Controlling the IP sabnzbd pulls newsgroup data with.

Post by lord_rahlly »

Thanks for the tip. Yeah I am hoping if I can get this cleanly implemented that it will get merged in. Would be a pain to have to change this for every update.
lord_rahlly
Newbie
Newbie
Posts: 8
Joined: December 22nd, 2013, 11:19 pm

Re: Controlling the IP sabnzbd pulls newsgroup data with.

Post by lord_rahlly »

sander wrote:Ah ... so you want to use the IP address already specificied in sabnzbd.ini as listening host, also as the outgoing IP address? Clever! Less risk on mistakes.

Use this:

sabnzbd.cfg.cherryhost()
Most Excellent tips. When I got home I implemented the changes

Code: Select all

# diff newswrapper.py newswrapper.old
119,123c119
<       try:
<               sock.bind((sabnzbd.cfg.cherryhost(), 0))
<       except:
<               pass
<       sock.connect((host, port))
---
>         sock.connect((host, port))
Then I added the line;

Code: Select all

cherryhost = 192.168.0.47
to the ini file. Works perfect;\

Just so you dont think I am some weirdo, the goal was to help with clear reporting on my network. Here is a screenshot of the reporting, sab is the IP related to all this. http://patentlystupid.com/sw/reporting.png
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Controlling the IP sabnzbd pulls newsgroup data with.

Post by sander »

Nice. However: Some homework for you:

What happens if SABnzbd listens on '::' (as it is on my system) or a specific public IPv6 address?
What happens with 'newszilla6.xs4all.nl' as one of the newsservers? If you have no IPv6 active, install miredo / teredo on your Fedora, and try it.

My goal of the above is to show that what you have programmed and works for you, will cause problems for other users. So I would just use the patch command based on your diff when you get a new SAB version (which only happens a few times a year).

EDIT:

I did some homework

With this code:

Code: Select all

        try:
            sock.bind((sabnzbd.cfg.cherryhost(), 0))
            logging.info('bind to %s worked OK', sabnzbd.cfg.cherryhost() )
        except:
            logging.info('bind to %s did not go well', sabnzbd.cfg.cherryhost() )
            pass
a host = :: results in:

Code: Select all

2014-10-03 07:17:59,429::INFO::[newswrapper:121] bind to :: worked OK
2014-10-03 07:17:59,431::INFO::[newswrapper:121] bind to :: worked OK
2014-10-03 07:17:59,432::INFO::[newswrapper:121] bind to :: worked OK
2014-10-03 07:17:59,433::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,435::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,436::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,438::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,441::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,444::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,445::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,447::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,448::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,449::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,450::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,451::INFO::[newswrapper:121] bind to :: worked OK
2014-10-03 07:17:59,451::INFO::[newswrapper:121] bind to :: worked OK
2014-10-03 07:17:59,452::INFO::[newswrapper:121] bind to :: worked OK
... which I don't understand.

A specific IPv6 address as 'host = ' results in about the same:

Code: Select all

2014-10-03 07:21:06,087::INFO::[newswrapper:121] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 worked OK
2014-10-03 07:21:06,088::INFO::[newswrapper:121] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 worked OK
2014-10-03 07:21:06,089::INFO::[newswrapper:121] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 worked OK
2014-10-03 07:21:06,090::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,093::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,096::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,097::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,099::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,100::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,106::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,106::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,107::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,109::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,118::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,119::INFO::[newswrapper:121] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 worked OK
2014-10-03 07:21:06,126::INFO::[newswrapper:121] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 worked OK
2014-10-03 07:21:06,128::INFO::[newswrapper:121] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 worked OK
Maybe the errors are caused by my IPv6-only newsservers? Yes, that must be it:

Code: Select all

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("::", 1234))
results in the following

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.gaierror: [Errno -9] Address family for hostname not supported
What I don't understand: that same socket is used for outgoing IPv4 and IPv4 connections, there apparently can NOT be AF_INET versus AF_INET6 in place.
lord_rahlly
Newbie
Newbie
Posts: 8
Joined: December 22nd, 2013, 11:19 pm

Re: Controlling the IP sabnzbd pulls newsgroup data with.

Post by lord_rahlly »

sander wrote:Nice. However: Some homework for you:

What happens if SABnzbd listens on '::' (as it is on my system) or a specific public IPv6 address?
What happens with 'newszilla6.xs4all.nl' as one of the newsservers? If you have no IPv6 active, install miredo / teredo on your Fedora, and try it.

My goal of the above is to show that what you have programmed and works for you, will cause problems for other users. So I would just use the patch command based on your diff when you get a new SAB version (which only happens a few times a year).
Hmm interesting point. I imagine some code could be put in place to only execute the bind if a proper parameter was in the ini file. TBH I am still flummoxed that reading the host setting is impossible.
EDIT:

I did some homework

With this code:

Code: Select all

        try:
            sock.bind((sabnzbd.cfg.cherryhost(), 0))
            logging.info('bind to %s worked OK', sabnzbd.cfg.cherryhost() )
        except:
            logging.info('bind to %s did not go well', sabnzbd.cfg.cherryhost() )
            pass
a host = :: results in:

Code: Select all

2014-10-03 07:17:59,429::INFO::[newswrapper:121] bind to :: worked OK
2014-10-03 07:17:59,431::INFO::[newswrapper:121] bind to :: worked OK
2014-10-03 07:17:59,432::INFO::[newswrapper:121] bind to :: worked OK
2014-10-03 07:17:59,433::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,435::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,436::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,438::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,441::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,444::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,445::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,447::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,448::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,449::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,450::INFO::[newswrapper:123] bind to :: did not go well
2014-10-03 07:17:59,451::INFO::[newswrapper:121] bind to :: worked OK
2014-10-03 07:17:59,451::INFO::[newswrapper:121] bind to :: worked OK
2014-10-03 07:17:59,452::INFO::[newswrapper:121] bind to :: worked OK
... which I don't understand.
It could be the fixed port you are using, you are binding too many connections to a single port, thats why I changed mine to use 0 for the port, this allows the OS to assign a port.
A specific IPv6 address as 'host = ' results in about the same:

Code: Select all

2014-10-03 07:21:06,087::INFO::[newswrapper:121] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 worked OK
2014-10-03 07:21:06,088::INFO::[newswrapper:121] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 worked OK
2014-10-03 07:21:06,089::INFO::[newswrapper:121] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 worked OK
2014-10-03 07:21:06,090::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,093::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,096::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,097::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,099::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,100::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,106::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,106::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,107::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,109::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,118::INFO::[newswrapper:123] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 did not go well
2014-10-03 07:21:06,119::INFO::[newswrapper:121] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 worked OK
2014-10-03 07:21:06,126::INFO::[newswrapper:121] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 worked OK
2014-10-03 07:21:06,128::INFO::[newswrapper:121] bind to 2001:0:bbbb:64c:e2:34a8:ad57:5619 worked OK
Maybe the errors are caused by my IPv6-only newsservers? Yes, that must be it:

Code: Select all

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("::", 1234))
results in the following

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.gaierror: [Errno -9] Address family for hostname not supported
What I don't understand: that same socket is used for outgoing IPv4 and IPv4 connections, there apparently can NOT be AF_INET versus AF_INET6 in place.
Yes this is what I saw when I specified a port. Once I removed the specified port it worked fine. Another way around this would be to change sabnzbd's setting to only open one connection to your nntp server.
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Controlling the IP sabnzbd pulls newsgroup data with.

Post by sander »

Ad "TBH I am still flummoxed that reading the host setting is impossible." ... what do you mean? You use sabnzbd.cfg.cherryhost(), which is that info, so ... ?
lord_rahlly
Newbie
Newbie
Posts: 8
Joined: December 22nd, 2013, 11:19 pm

Re: Controlling the IP sabnzbd pulls newsgroup data with.

Post by lord_rahlly »

sander wrote:Ad "TBH I am still flummoxed that reading the host setting is impossible." ... what do you mean? You use sabnzbd.cfg.cherryhost(), which is that info, so ... ?
sabnzbd.cfg.cherryhost() returns the value of cherryhost from the ini.
sabnzbd.cfg.host() returns an error, this value is the one the system pays attention to for the web server IP for accessing the UI. That is why I felt it would be best to use this value, since its already being referenced if you want to specify an IP it should be valid and there is some value checking done against this in the configure or cfg code from what I have read.
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Controlling the IP sabnzbd pulls newsgroup data with.

Post by sander »

lord_rahlly wrote:
sander wrote:Ad "TBH I am still flummoxed that reading the host setting is impossible." ... what do you mean? You use sabnzbd.cfg.cherryhost(), which is that info, so ... ?
sabnzbd.cfg.cherryhost() returns the value of cherryhost from the ini.
sabnzbd.cfg.host() returns an error, this value is the one the system pays attention to for the web server IP for accessing the UI. That is why I felt it would be best to use this value, since its already being referenced if you want to specify an IP it should be valid and there is some value checking done against this in the configure or cfg code from what I have read.
No, sabnzbd.cfg.cherryhost() returns the value of of 'host' in the 'misc' part of sabnzbd.ini. See the source:

Code: Select all

$ grep -i host sabnzbd/cfg.py
...
cherryhost = OptionStr('misc', 'host', DEF_HOST)
HTH
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Controlling the IP sabnzbd pulls newsgroup data with.

Post by sander »

Attention: The following is only relevant for the IPv6 case ... explaining the problems I see when host is '::':

Code in newswrapper.py from 119 on is now:

Code: Select all

        # bind-before-connect:
        logging.info('cherryhost is %s. Value of (NNTP) host is %s', sabnzbd.cfg.cherryhost(), host )
        if sock.family == socket.AF_INET:
            logging.info('bind-before-connect: socket type is ipv4')
        if sock.family == socket.AF_INET6:
            logging.info('bind-before-connect: socket type is ipv6')
        try:
            sock.bind((sabnzbd.cfg.cherryhost(), 0))
            logging.info('bind to %s worked OK.', sabnzbd.cfg.cherryhost())
        except:
            logging.info('bind to %s did not go well.', sabnzbd.cfg.cherryhost())
            pass
Result of the logging:

Code: Select all

2014-10-04 00:27:28,270::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is weathergirl-ipv6.tele2.net
2014-10-04 00:27:28,270::INFO::[newswrapper:124] bind-before-connect: socket type is ipv6
2014-10-04 00:27:28,271::INFO::[newswrapper:127] bind to :: worked OK.
2014-10-04 00:27:30,310::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is server.testing.com
2014-10-04 00:27:30,311::INFO::[newswrapper:122] bind-before-connect: socket type is ipv4
2014-10-04 00:27:30,311::INFO::[newswrapper:129] bind to :: did not go well.
2014-10-04 00:27:32,314::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is server.testing.com
2014-10-04 00:27:32,315::INFO::[newswrapper:122] bind-before-connect: socket type is ipv4
2014-10-04 00:27:32,315::INFO::[newswrapper:129] bind to :: did not go well.
2014-10-04 00:27:43,487::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is weathergirl-ipv6.tele2.net
2014-10-04 00:27:43,488::INFO::[newswrapper:124] bind-before-connect: socket type is ipv6
2014-10-04 00:27:43,488::INFO::[newswrapper:127] bind to :: worked OK.
2014-10-04 00:27:43,491::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is weathergirl-ipv6.tele2.net
2014-10-04 00:27:43,492::INFO::[newswrapper:124] bind-before-connect: socket type is ipv6
2014-10-04 00:27:43,493::INFO::[newswrapper:127] bind to :: worked OK.
2014-10-04 00:27:43,513::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is server.testing.com
2014-10-04 00:27:43,514::INFO::[newswrapper:122] bind-before-connect: socket type is ipv4
2014-10-04 00:27:43,515::INFO::[newswrapper:129] bind to :: did not go well.
2014-10-04 00:27:43,517::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is server.testing.com
2014-10-04 00:27:43,517::INFO::[newswrapper:122] bind-before-connect: socket type is ipv4
2014-10-04 00:27:43,518::INFO::[newswrapper:129] bind to :: did not go well.
2014-10-04 00:27:43,520::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is reader.i-telligent.com
2014-10-04 00:27:43,521::INFO::[newswrapper:122] bind-before-connect: socket type is ipv4
2014-10-04 00:27:43,522::INFO::[newswrapper:129] bind to :: did not go well.
2014-10-04 00:27:43,523::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is reader.i-telligent.com
2014-10-04 00:27:43,524::INFO::[newswrapper:122] bind-before-connect: socket type is ipv4
2014-10-04 00:27:43,525::INFO::[newswrapper:129] bind to :: did not go well.
2014-10-04 00:27:43,527::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is reader.i-telligent.com
2014-10-04 00:27:43,528::INFO::[newswrapper:122] bind-before-connect: socket type is ipv4
2014-10-04 00:27:43,530::INFO::[newswrapper:129] bind to :: did not go well.
2014-10-04 00:27:43,536::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is reader.i-telligent.com
2014-10-04 00:27:43,536::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is newsreader3.eweka.nl
2014-10-04 00:27:43,537::INFO::[newswrapper:122] bind-before-connect: socket type is ipv4
2014-10-04 00:27:43,537::INFO::[newswrapper:122] bind-before-connect: socket type is ipv4
2014-10-04 00:27:43,538::INFO::[newswrapper:129] bind to :: did not go well.
2014-10-04 00:27:43,538::INFO::[newswrapper:129] bind to :: did not go well.
2014-10-04 00:27:43,541::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is newsreader3.eweka.nl
2014-10-04 00:27:43,542::INFO::[newswrapper:122] bind-before-connect: socket type is ipv4
2014-10-04 00:27:43,542::INFO::[newswrapper:129] bind to :: did not go well.
2014-10-04 00:27:43,544::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is newsreader3.eweka.nl
2014-10-04 00:27:43,544::INFO::[newswrapper:122] bind-before-connect: socket type is ipv4
2014-10-04 00:27:43,545::INFO::[newswrapper:129] bind to :: did not go well.
2014-10-04 00:27:43,557::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is newszilla6.xs4all.nl
2014-10-04 00:27:43,558::INFO::[newswrapper:124] bind-before-connect: socket type is ipv6
2014-10-04 00:27:43,558::INFO::[newswrapper:127] bind to :: worked OK.
2014-10-04 00:27:43,560::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is newszilla6.xs4all.nl
2014-10-04 00:27:43,561::INFO::[newswrapper:124] bind-before-connect: socket type is ipv6
2014-10-04 00:27:43,563::INFO::[newswrapper:127] bind to :: worked OK.
2014-10-04 00:27:43,566::INFO::[newswrapper:120] cherryhost is ::. Value of (NNTP) host is newszilla6.xs4all.nl
2014-10-04 00:27:43,566::INFO::[newswrapper:124] bind-before-connect: socket type is ipv6
2014-10-04 00:27:43,567::INFO::[newswrapper:127] bind to :: worked OK.
The above explains to me that as soon as con(...) is called, the socket.socket initialisation has already be done, so the AF_INET or AF_INET6 is already in place. So apparantly SABnzbd has already determined to destination NNTP server's family type, and has the socket's family type to that. And the bind-before-connect should bind to the same family type as the NNTP server's family type. And that is logical.

To be continued.
User avatar
sander
Release Testers
Release Testers
Posts: 8832
Joined: January 22nd, 2008, 2:22 pm

Re: Controlling the IP sabnzbd pulls newsgroup data with.

Post by sander »

OK. I got it working: 100 real, dowloading IPv6 connections to a certain IPv6-newsserver, getting line-speed (well: line-speed of my laptop's ethernet card, so only 100 Mbps).

Technical details: I defined 200 public IPv6 address on my laptop's network interface. For each IPv6 newsserver connection SAB binds to a random public IPv6 address from that list as the source address.

The code is quite ugly, and needs the "ip" command (to get the known IPv6 addresses), so Linux (or Unix) only.

sabnzbd/newswrapper.py, starting at line 119:

Code: Select all

        # First some bind-before-connect:
        logging.info('cherryhost is %s. Value of (NNTP) host is %s', sabnzbd.cfg.cherryhost(), host )
        if sock.family == socket.AF_INET:
            logging.info('bind-before-connect: socket type is ipv4')
        if sock.family == socket.AF_INET6:
            # sock is an IPv6 socket
            logging.info('bind-before-connect: socket type is ipv6')
            #interface = 'wlan0'
            interface = 'eth0'
            cmd = 'ip -6 addr show dev ' + interface
            ipv6list = []
            import os
            # get all public IPv6 addresses on the named interface:
            for thisline in os.popen(cmd).readlines():
                if 'inet6 2' in thisline:
                    # skip fe80, ::1, etc
                    ipv6list.append(thisline.split()[1].split('/')[0])
            # ... and now pick a random IPv6 addresss from that list
            import random
            randnumber = random.randint(0,len(ipv6list)-1)
            randipv6 = ipv6list[randnumber]
            # ... and try to bind to that before the connect
            try:
                sock.bind((randipv6, 0))
                logging.info('bind to %s worked OK.', randipv6)
            except:
                logging.info('bind to %s did not go well.', randipv6)
                pass
Some proof (with some info replaced):

Code: Select all

2014-10-05 08:56:35,531::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:95 worked OK.
2014-10-05 08:56:35,545::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:71 worked OK.
2014-10-05 08:56:35,555::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:161 worked OK.
2014-10-05 08:56:35,561::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:109 worked OK.
2014-10-05 08:56:35,588::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:164 worked OK.
2014-10-05 08:56:35,593::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:68 worked OK.
2014-10-05 08:56:35,596::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:66 worked OK.
2014-10-05 08:56:35,608::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:168 worked OK.
2014-10-05 08:56:35,623::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:97 worked OK.
2014-10-05 08:56:35,632::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:151 worked OK.
2014-10-05 08:56:35,648::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:171 worked OK.
2014-10-05 08:56:35,662::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:89 worked OK.
2014-10-05 08:56:35,672::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:184 worked OK.
2014-10-05 08:56:35,674::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:91 worked OK.
2014-10-05 08:56:35,680::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:188 worked OK.
2014-10-05 08:56:35,705::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:29 worked OK.
2014-10-05 08:56:35,707::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:36 worked OK.
2014-10-05 08:56:35,708::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:24 worked OK.
2014-10-05 08:56:35,725::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:121a worked OK.
2014-10-05 08:56:35,737::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:10 worked OK.
2014-10-05 08:56:35,747::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:70 worked OK.
2014-10-05 08:56:35,748::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:137 worked OK.
2014-10-05 08:56:35,771::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:155 worked OK.
2014-10-05 08:56:35,796::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:184 worked OK.
2014-10-05 08:56:35,799::INFO::[newswrapper:139] bind to 2002:abcd:1234:1:5cd0:2cba:16ee:109 worked OK.

Code: Select all

2014-10-05 08:56:25,692::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,692::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,693::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,693::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,693::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,694::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,694::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,695::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,695::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,695::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,695::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,696::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,696::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,698::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,704::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,704::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,708::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,818::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,933::INFO::[downloader:577] Connecting [email protected]:119 finished
2014-10-05 08:56:25,934::INFO::[downloader:577] Connecting [email protected]:119 finished
Remark: normally newsservers don't like it when one account comes from different source addresses ("account sharing"). I'm exactly doing that with the above code, which works great for the newsserver I used.
Post Reply