public IEnumerable <NormalizedNetwork> ExtractNetworks(IEnumerable <string> networkFilePaths) { foreach (var networkFilePath in networkFilePaths) { foreach (var section in this.Parser.RetrieveSections(networkFilePath)) { var network = NormalizedNetwork.TryParseFromSection(section); if (network != null) { if (this.OrganizationIdsToOrganizations.Count > 0) { network.FindExternalOrganization(section, this.OrganizationIdsToOrganizations); } else if (network.ExternalOrganization == null && this.OrganizationNamesToOrganizations.Count > 0) { network.FindExternalOrganization(section, this.OrganizationNamesToOrganizations); } var networkLocation = network.Location; var organizationLocation = network.ExternalOrganization?.Location; if (networkLocation == null || !networkLocation.AddressSeemsValid()) { if (organizationLocation != null && organizationLocation.AddressSeemsValid()) { network.Location = organizationLocation; } } yield return(network); } } } }
public static NormalizedNetwork TryParseFromSection(RawWhoisSection section) { if (networkTypes.Contains(section.Type)) { var network = new NormalizedNetwork() { Location = NormalizedLocation.TryParseFromSection(section), AuthArea = NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, authAreaFields), OriginAS = NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, originASFields), Status = NormalizationUtils.FindFirstMatchingFieldValueInRecords(section, statusFields) }; var candidateRanges = NormalizationUtils.FindAllMatchingFieldValuesInRecords(section, ipRangeFields); if (candidateRanges != null) { IPAddressRange range = null; foreach (var candidateRange in candidateRanges) { if (IPAddressRange.TryParse(candidateRange, out range)) { break; } } network.IPRange = range; } else { // TODO: Some networks do not have an explicit IP range but maybe we can get it from the Auth Area or from the ID? } NormalizationUtils.ExtractCommonRecordMetadata(section, section.Id, nameFields, network); return(network); } return(null); }