Beispiel #1
0
        public IHttpActionResult GetIPByHostname(string hostName, QueryType type)
        {
            var client = new LookupClient();
            IDnsQueryResponse result = null;
            RecordDto         record = new RecordDto()
            {
                HostName = new List <string>()
                {
                    hostName
                }, Type = type.ToString()
            };

            switch (type)
            {
            default:
            case QueryType.A:
                result           = _client.Query(hostName, QueryType.A);
                record.IPAddress = result.Answers.ARecords().FirstOrDefault().Address.ToString();
                break;

            case QueryType.AAAA:

                result           = _client.Query(hostName, QueryType.AAAA);
                record.IPAddress = result.Answers.AaaaRecords().FirstOrDefault().Address.ToString();
                break;
            }
            ;
            var linkedResource = new
            {
                value = record,
                links = CreateLinks(record)
            };

            return(Ok(linkedResource));
        }
Beispiel #2
0
        public IHttpActionResult GetHostNameByIP1([FromUri] string ipAddress)
        {
            IDnsQueryResponse result   = null;
            RecordDto         hostName = new RecordDto()
            {
                IPAddress = ipAddress
            };

            result            = _client.QueryReverse(IPAddress.Parse(ipAddress));
            hostName.HostName = result.Answers.PtrRecords().Select(name => name.PtrDomainName.ToString());
            return(Ok(hostName));
        }
Beispiel #3
0
        //  Add HATOEAS
        private IEnumerable <Link> CreateLinks(RecordDto record)
        {
            var links = new[]
            {
                new Link
                {
                    Method = "GET",
                    Rel    = "self",
                    Href   = Url.Link("GetIPByHostname", new { hostname = record.HostName.FirstOrDefault() })
                },
                new Link
                {
                    Method = "GET",
                    Rel    = "x",
                    Href   = Url.Link("GetHostNameByIP", new { ipAddress = record.IPAddress })
                },
            };

            return(links);
        }