zu1k / nali

An offline tool for querying IP geographic information and CDN provider. 一个查询IP地理信息和CDN服务提供商的离线终端工具.
https://github.com/zu1k/nali
MIT License
3.74k stars 340 forks source link

Add json format output. #165

Closed M09Ic closed 1 year ago

M09Ic commented 1 year ago

Cleaned up the code and solved multiple problems in pr #163

The specific changes compared to #163:

example1:

echo 1.1.1.1 | ./nali.exe -j | jq
{
  "type": 0,
  "ip": "1.1.1.1",
  "text": "澳大利亚 APNIC/CloudFlare公共DNS服务器",
  "source": "qqwry",
  "info": {
    "country": "澳大利亚",
    "area": "APNIC/CloudFlare公共DNS服务器"
  }
}

example2:

image

M09Ic commented 1 year ago

with fatal: https://github.com/zu1k/nali/pull/163#issuecomment-1554537648

I did not reproduce the error, so if it still exists, please point it out.

zu1k commented 1 year ago

This PR breaks the original output format, please fix it.

without nali

❯ nslookup fake.com
Server:     192.168.226.100
Address:    192.168.226.100#53

Name:   fake.com
Address: 198.18.59.212

with old version nali

❯ nslookup fake.com | nali
Server:     192.168.226.100 [局域网 对方和您在同一内部网] 
Address:    192.168.226.100 [局域网 对方和您在同一内部网] #53

Name:   fake.com
Address: 198.18.59.212 [IANA 保留地址]

with this pr version nali

❯ nslookup fake.com | ./nali
Server:     
192.168.226.100 [局域网 对方和您在同一内部网]
Address:    
192.168.226.100 [局域网 对方和您在同一内部网] 
#53

Name:   
Name:   fake.com
Address: 
198.18.59.212 [IANA 保留地址]
zu1k commented 1 year ago

with fatal: #163 (comment)

I did not reproduce the error, so if it still exists, please point it out.

https://github.com/zu1k/nali/pull/163#discussion_r1198949818

zu1k commented 1 year ago

If we need to output the database name, I recommend using the real database name defined in the configuration file, because the user may modify it, and the same database format may have multiple sources and therefore may have different names.

https://github.com/zu1k/nali/blob/748c5cf4a88241861047582db2b845b022aa76df/internal/db/type.go#L16-L17

- name: geoip2
  format: mmdb
  file: GeoIP2-City.mmdb
- name: geolite2
  format: mmdb
  file: GeoLite2-City.mmdb
- name: ipinfo
  format: mmdb
  file: ipinfo_country.mmdb
- name: dbip
  format: mmdb
  file: dbip.mmdb
M09Ic commented 1 year ago

If we need to output the database name, I recommend using the real database name defined in the configuration file, because the user may modify it, and the same database format may have multiple sources and therefore may have different names.

https://github.com/zu1k/nali/blob/748c5cf4a88241861047582db2b845b022aa76df/internal/db/type.go#L16-L17

- name: geoip2
  format: mmdb
  file: GeoIP2-City.mmdb
- name: geolite2
  format: mmdb
  file: GeoLite2-City.mmdb
- name: ipinfo
  format: mmdb
  file: ipinfo_country.mmdb
- name: dbip
  format: mmdb
  file: dbip.mmdb

Has been changed to return the same value for dbif.Name func as db.Name field.

M09Ic commented 1 year ago

This PR breaks the original output format, please fix it.

without nali

❯ nslookup fake.com
Server:       192.168.226.100
Address:  192.168.226.100#53

Name: fake.com
Address: 198.18.59.212

with old version nali

❯ nslookup fake.com | nali
Server:       192.168.226.100 [局域网 对方和您在同一内部网] 
Address:  192.168.226.100 [局域网 对方和您在同一内部网] #53

Name: fake.com
Address: 198.18.59.212 [IANA 保留地址]

with this pr version nali

❯ nslookup fake.com | ./nali
Server:       
192.168.226.100 [局域网 对方和您在同一内部网]
Address:  
192.168.226.100 [局域网 对方和您在同一内部网] 
#53

Name: 
Name: fake.com
Address: 
198.18.59.212 [IANA 保留地址]

resolve it in commit https://github.com/zu1k/nali/pull/165/commits/56be0c61cae1ce6e653fefcca974e1be371a6a91

zu1k commented 1 year ago

Sorry for the late, had too many things a while ago. This PR looks good so far, I'm going to merge it!