I have the following output from nmap and i am trying to split into the sections like nmap has it, like the following:
PORT | STATE | SERVICE | VERSION
The output would look like this:
2000/tcp open cisco-sccp?
3000/tcp open http Apache httpd 2.2.3 ((CentOS))
I tried using the string.split() but it keeps giving me everything in its own entry, so ultimately what i am trying to get is the "Apache httpd 2.2.3 ((CentOS))" but i can't get that at all, it keeps putting every word in an entry. I even tried
re.split('\s+', string)
But that also yields the same result. Any help is very much appreciated.
Not a general solution, but for this specific example, I think just specifying a maxsplit
would work:
In [7]: re.split(r'\s+', '3000/tcp open http Apache httpd 2.2.3 ((CentOS))', 3)
Out[7]: ['3000/tcp', 'open', 'http', 'Apache httpd 2.2.3 ((CentOS))']
That tells it to split 3 times, but then just leave the rest as-is.
Short lines just are shorter and don't have 4 items:
In [8]: re.split(r'\s+', '2000/tcp open cisco-sccp?', 3)
Out[8]: ['2000/tcp', 'open', 'cisco-sccp?']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.