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

Add json format output. #165

Merged
merged 9 commits into from
Aug 24, 2023
Merged

Add json format output. #165

merged 9 commits into from
Aug 24, 2023

Conversation

M09Ic
Copy link
Contributor

@M09Ic M09Ic commented May 20, 2023

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

The specific changes compared to #163:

  • delete jsonline format, combine to one json per line.
  • now it will not destroy the original behavior.
  • add source fields to json output.
  • fixed some issues you pointed out in pr 163
  • if set -j/--json flag, auto enable clean output(output json data only, ignore other data)

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
Copy link
Contributor Author

M09Ic commented May 20, 2023

with fatal: #163 (comment)

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

@zu1k
Copy link
Owner

zu1k commented May 21, 2023

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 zu1k closed this May 21, 2023
@zu1k zu1k reopened this May 21, 2023
@zu1k
Copy link
Owner

zu1k commented May 21, 2023

with fatal: #163 (comment)

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

#163 (comment)

@zu1k
Copy link
Owner

zu1k commented May 21, 2023

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.

nali/internal/db/type.go

Lines 16 to 17 in 748c5cf

type DB struct {
Name string

- 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
Copy link
Contributor Author

M09Ic commented May 21, 2023

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.

nali/internal/db/type.go

Lines 16 to 17 in 748c5cf

type DB struct {
Name string

- 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
Copy link
Contributor Author

M09Ic commented May 21, 2023

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 56be0c6

@zu1k
Copy link
Owner

zu1k commented Aug 24, 2023

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

@zu1k zu1k merged commit 77c5bee into zu1k:master Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants