Python3
OSX 10.13.2
I am trying to make FACEBOOK_WHITELIST
in order to prevent malicious attack from the internet when listening to webhook
I am in the process of getting the IP addresses. The command is very simple just whois
, pipe
, and grep
.
Problem:
def test():
import subprocess
ps = subprocess.Popen(
["whois", "-h", "whois.radb.net", "--", "'-i origin AS32934'"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
output = subprocess.check_output(('grep', 'route'), stdin=ps.stdout)
ps.wait()
Trackback:
---------------------------------------------------------------------------
CalledProcessError Traceback (most recent call last)
<ipython-input-28-8d5c434d09bd> in <module>()
5 stderr=subprocess.STDOUT
6 )
----> 7 output = subprocess.check_output(('grep', 'route'), stdin=ps.stdout)
8 ps.wait()
~/.pyenv/versions/3.6.4/lib/python3.6/subprocess.py in check_output(timeout, *popenargs, **kwargs)
334
335 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 336 **kwargs).stdout
337
338
~/.pyenv/versions/3.6.4/lib/python3.6/subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
416 if check and retcode:
417 raise CalledProcessError(retcode, process.args,
--> 418 output=stdout, stderr=stderr)
419 return CompletedProcess(process.args, retcode, stdout, stderr)
420
CalledProcessError: Command '('grep', 'route')' returned non-zero exit status 1.
Then I tried smaller function call. Neither of them are work. First one is single string in single quote
In [46]: ps = subprocess.Popen(["whois", "-h", "whois.radb.net", "--", "'-i origin AS32934'"])
...:
...:
In [47]: % No entries found for the selected source(s).
Second one is split string into multiple double quoted string
In [48]: ps = subprocess.Popen(["whois", "-h", "whois.radb.net", "--", "'-i", "origin", "AS32934'"])
In [49]: % No entries found for the selected source(s).
% No entries found for the selected source(s).
% No entries found for the selected source(s).
Where am I wrong?
Update:
@Jean-François Fabre
In [49]: ps = subprocess.Popen(["whois", "-h", "whois.radb.net", "--", "-i", "origin", "AS32934"])
In [50]: %% Attribute name after "-i" is invalid or unsupported.
% No entries found for the selected source(s).
aut-num: AS32934
as-name: Facebook
descr: Facebook
member-of: AS-FACEBOOK
import: from AS-ANY accept ANY AND NOT {0.0.0.0/0}
export: to AS-ANY announce AS-FACEBOOK AND NOT {0.0.0.0/0}
admin-c: FBNetEng
tech-c: FBNetEng
notify: noc@fb.com
mnt-by: MAINT-AS32934
changed: vvasilev@fb.com 20170627 #21:09:05Z
source: RADB
References:
CallProcessError
pipe grep