find IP address by domain in go

0 votes

I am using below code for an API to find ip address for a given domain:

func IPFinder(c *gin.Context) {
    var domain models.Domain
    c.BindJSON(&domain)
    addr, err := net.LookupIP(domain.DomainName)
    if err != nil {
        c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
    } else {
        c.JSON(http.StatusOK, gin.H{"ip_address": addr})
    }
    return
}

For the below request:

{
    "domain_name": "yahoo.com"
}

getting response as :

{
    "ip_address": [
        "2404:6800:4002:80a::200e",
        "172.217.167.46"
    ]
}

Here this LookupIP method is giving the slice containing ipv4 and ipv6 address of that domain. Is there any other way of any other 3rd party lib in GoLang using which I can get output containing only the ip address like below :

{
    "ip_address": "172.217.167.46"
}

Feb 16 in Cyber Security & Ethical Hacking by Edureka
• 5,460 points
21 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Cyber Security & Ethical Hacking

+1 vote
1 answer

How to find IP address of nodes in my network?

The IP address of the nodes connected ...READ MORE

answered Feb 9, 2019 in Cyber Security & Ethical Hacking by Omkar
• 69,190 points
1,181 views
0 votes
1 answer

IP address by Domain Name

The code you provided is accurate. Perhaps ...READ MORE

answered Feb 24 in Cyber Security & Ethical Hacking by Edureka
• 5,460 points
29 views
0 votes
1 answer

How to find MAC address using IP address?

To find the MAC address, run this ...READ MORE

answered Feb 9, 2019 in Cyber Security & Ethical Hacking by Omkar
• 69,190 points
898 views
0 votes
1 answer

Private IP Address Identifier in Regular Expression

I'm assuming you want to match these ...READ MORE

answered Feb 16 in Cyber Security & Ethical Hacking by Edureka
• 5,460 points
124 views
0 votes
0 answers

Find IP address of directly connected device

Is it possible to determine the IP ...READ MORE

Feb 16 in Cyber Security & Ethical Hacking by Edureka
• 5,460 points
59 views
0 votes
1 answer

How do i check a ip address range whether it falls in Class A,Class B,Class C

class NetworkId{ static String findClass(String str){ int index = ...READ MORE

answered Feb 16 in Cyber Security & Ethical Hacking by Edureka
• 5,760 points
35 views
0 votes
0 answers
0 votes
2 answers

Finding local IP addresses using Python's stdlib

import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s ...READ MORE

answered Mar 30, 2020 in Python by anonymous
1,587 views
0 votes
1 answer

how to find ip address in cmd

1. Open the Command Prompt.   a. Click the Start icon, ...READ MORE

answered Feb 9 in Cyber Security & Ethical Hacking by Edureka
• 5,760 points
33 views
0 votes
1 answer

difference between mac address and ip address

MAC Address IP Address MAC Address stands for Media ...READ MORE

answered Feb 8 in Cyber Security & Ethical Hacking by Edureka
• 5,760 points
30 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP