mirror of
https://github.com/ameshkov/dnslookup.git
synced 2026-04-27 06:26:24 +03:00
[GH-ISSUE #64] Option to get only the IP as result #44
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/dnslookup#44
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kelvinkad on GitHub (Feb 12, 2024).
Original GitHub issue: https://github.com/ameshkov/dnslookup/issues/64
How can I get only the IP as result of the command?
For example, when I use "dnslookup google.com tls://dns.adguard.com"
I`d like to get only 142.250.219.174 as result.
@mohshami commented on GitHub (Feb 12, 2024):
You can do it like this
Hope that helps
@kelvinkad commented on GitHub (Feb 12, 2024):
Yeah! It helped a lot! Thanks
@mohshami commented on GitHub (Feb 12, 2024):
You are most welcome :)
@kelvinkad commented on GitHub (May 1, 2024):
Hello, I faced a problem with this command we talked about. Maybe you can help me.
When I run, for example: JSON=1 dnslookup google.com tls://dns.adguard.com | jq -r '.Answer[].A', like you suggested me to get only the IP, I get one, two, three dns addresses
Is there a way to grab only one? And sometimes the first and second addresses are NULL, so I can`t select this, just the valid address, that is maybe the third value.
otherwise, I get this error:
jq: error (at :41): Cannot iterate over null (null)
Do you know how can I solve this?
@mohshami commented on GitHub (May 3, 2024):
This normally happens when the reply doesn't contain the required field, what is the output without jq part?
@kelvinkad commented on GitHub (May 5, 2024):
Let me give you one full example
The following command:
JSON=1 dnslookup cfs10.blog.daum.net tls://dns.adguard-dns.com | jq -r '.Answer[].A'
returns this:
null
null
121.53.201.236
If I repeat the same command withou jq the answer is this:
{
"Id": 42595,
"Response": true,
"Opcode": 0,
"Authoritative": false,
"Truncated": false,
"RecursionDesired": true,
"RecursionAvailable": true,
"Zero": false,
"AuthenticatedData": false,
"CheckingDisabled": false,
"Rcode": 0,
"Question": [
{
"Name": "cfs10.blog.daum.net.",
"Qtype": 1,
"Qclass": 1
}
],
"Answer": [
{
"Hdr": {
"Name": "cfs10.blog.daum.net.",
"Rrtype": 5,
"Class": 1,
"Ttl": 600,
"Rdlength": 17
},
"Target": "t1.int.daumcdn.net."
},
{
"Hdr": {
"Name": "t1.int.daumcdn.net.",
"Rrtype": 5,
"Class": 1,
"Ttl": 600,
"Rdlength": 27
},
"Target": "t1-int-jzdtavpl.kgslb.com."
},
{
"Hdr": {
"Name": "t1-int-jzdtavpl.kgslb.com.",
"Rrtype": 1,
"Class": 1,
"Ttl": 60,
"Rdlength": 4
},
"A": "121.53.202.238"
}
],
"Ns": null,
"Extra": null,
"elapsed": 1067907345
}
See that using jq, the answer comes with null, null and then the answer I want, the A record?
How Do I exclude the null results from the answer? And sometimes the answer comes with 2 or 3 ip`s, like this:
null
null
94.154.114.212
94.154.114.214
94.154.114.213
94.154.114.215
I would like to exclude this null results AND grab only ONE address, so the answer for the command I want would be like:
94.154.114.212
Only one ip, only one line, only one result.
You think this is possible?
@mohshami commented on GitHub (May 5, 2024):
That's more of a jq thing at this point. You can do something like this (with the json you provided)
jq '.Answer[] | select (.A) | .A'
and you'll get
"121.53.202.238"
@kelvinkad commented on GitHub (May 6, 2024):
That's great. The null answer was excluded. Now I just need to figured out how to grab only one answer when there are more than 2 dns addresses, but I'll see if I can.
Thank you very much for your help even though the subject is not about your tool.
@mohshami commented on GitHub (May 6, 2024):
Well I only have a few lines in dnslookup, I'm just here to help :)