Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一行多个IP会导致只有部分显示结果 #64

Closed
ivan0-1 opened this issue Oct 25, 2021 · 2 comments
Closed

一行多个IP会导致只有部分显示结果 #64

ivan0-1 opened this issue Oct 25, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@ivan0-1
Copy link

ivan0-1 commented Oct 25, 2021

目前状况:

167.71.18.94 207.154.224.242 [美国 纽约市DigitalOcean云公司]  47.106.88.234 120.246.107.20 [中国 移动]  111.59.153.137 118.123.213.221 172.105.90.107 207.180.236.214 [美国 ]  143.198.50.119 [美国 ]  165.232.161.232 182.150.48.140 [四川省成都市 电信]

分析:看了一下代码,正则匹配是正常的。出错的原因是ip同时命中了ipv4和domain的正则,sort之后有的ip在数组中是ipv4匹配在前,有的是domain在前,ipv4在前的结果就被domain的覆盖了,而domain查询结果为空,导致最终结果为空。

Element[0] = &{[%!s(int=0) %!s(int=12)] %!s(entity.EntityType=2) 167.71.18.94 }
Element[1] = &{[%!s(int=0) %!s(int=12)] %!s(entity.EntityType=0) 167.71.18.94 }
Element[2] = &{[%!s(int=13) %!s(int=28)] %!s(entity.EntityType=0) 207.154.224.242 }
Element[3] = &{[%!s(int=13) %!s(int=28)] %!s(entity.EntityType=2) 207.154.224.242 }

解决方案:
核心原因是正则问题,所以我的修复方式是修改正则,增加domain匹配的时候匹配一级域名,一级域名是在cdn.json里找出来的
`[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})*.(cc|cloud|com.cn|com|co|cn|io|me|net|org|tv)``
ps:其实改成同个ip多次匹配返回非空那个比较合理,但不会写go。。。。
pps:正则改成这样肯定也会有问题,但我一般不查cdn问题不大

结果:

➜  nali git:(master) ✗ go run . 167.71.18.94 207.154.224.242 47.106.88.234 120.246.107.20 111.59.153.137 118.123.213.221 172.105.90.107 207.180.236.214 143.198.50.119 165.232.161.232 182.150.48.140
167.71.18.94 [美国 ]  207.154.224.242 [美国 纽约市DigitalOcean云公司]  47.106.88.234 [广东省深圳市 阿里云]  120.246.107.20 [中国 移动]  111.59.153.137 [广西南宁市 移动]  118.123.213.221 [四川省成都市 电信]  172.105.90.107 [德国 黑森州法兰克福Linode数据中心]  207.180.236.214 [美国 ]  143.198.50.119 [美国 ]  165.232.161.232 [美国 ]  182.150.48.140 [四川省成都市 电信]
@zu1k zu1k self-assigned this Oct 26, 2021
@zu1k zu1k added the bug Something isn't working label Oct 26, 2021
zu1k pushed a commit that referenced this issue Oct 26, 2021
@zu1k
Copy link
Owner

zu1k commented Oct 26, 2021

感谢反馈,试一下 https://github.com/zu1k/nali/releases/tag/v0.3.2

@ivan0-1
Copy link
Author

ivan0-1 commented Oct 26, 2021

确认已修复,感谢。
close

@ivan0-1 ivan0-1 closed this as completed Oct 26, 2021
zu1k pushed a commit that referenced this issue Jul 21, 2022
zu1k pushed a commit that referenced this issue Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants