Ejemplo n.º 1
0
        public static async Task <HostInfoDto> StringToAbsoluteUriAsync(string uriString)
        {
            var hostModel = new HostInfoDto();

            if (!uriString.Contains(Uri.SchemeDelimiter))
            {
                uriString = Uri.UriSchemeHttp + Uri.SchemeDelimiter + uriString;
            }

            if (Uri.TryCreate(uriString, UriKind.RelativeOrAbsolute, out var resultUri))
            {
                try
                {
                    IPAddress[] addressesOfHost = await Dns.GetHostAddressesAsync(resultUri.DnsSafeHost);

                    if (addressesOfHost.Length > 0)
                    {
                        hostModel.Uri      = resultUri.ToString();
                        hostModel.SafeHost = resultUri.DnsSafeHost;
                        hostModel.Ips      = addressesOfHost
                                             .Select(a => a.ToString())
                                             .ToList();
                        return(hostModel);
                    }
                }
                catch (System.Net.Sockets.SocketException)
                {
                    return(null);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public async Task <List <HostInfoDto> > CheckDomainNames(IEnumerable <string> domains)
        {
            var hostInfoDtos = new List <HostInfoDto>();

            var tasks = domains
                        .Select(async domain =>
            {
                var host = await UriHelper.StringToAbsoluteUriAsync(domain);
                if (host != null)
                {
                    var hostInfoDto = new HostInfoDto()
                    {
                        Ips      = host.Ips,
                        SafeHost = host.SafeHost,
                        Uri      = host.Uri
                    };

                    var response = await _httpClient.GetAsync(host.Uri);

                    // analyze cookies
                    // analyze url
                    // analyze html content
                    // analyze scripts

                    var headersTechs = ContentAnalyzer.AnalyzeHeaders(response.Headers);
                    hostInfoDto.Techs.AddRange(headersTechs);

                    hostInfoDtos.Add(hostInfoDto);
                }
            });

            await Task.WhenAll(tasks);

            return(hostInfoDtos);
        }