private bool IsInterestingLink(string href) { if (href != string.Empty) { if (href.StartsWith("mailto:")) { string email = href.Substring(7, (href.Contains("?") ? href.IndexOf('?') : href.Length) - 7); FoundEmails.AddUniqueItem(email); } else if (href.StartsWith("ftp:")) { return(true); } else if (href.StartsWith("http:")) { return(true); } else if (href.StartsWith("https:")) { return(true); } else if (href.StartsWith("telnet:")) { return(true); } else if (href.StartsWith("ldap:")) { return(true); } else { try { Uri u = new Uri(href); if (u.HostNameType != UriHostNameType.Dns) { return(true); } } catch (UriFormatException) { if (!href.StartsWith("#")) { return(true); } } } } return(false); }
/// <summary> /// Devuelve true si el link es interesante ya que contiene una IP o una ruta, el resto de links se desprecian /// </summary> /// <returns></returns> private bool IsInterestingLink(string href) { if (href != string.Empty) { if (href.StartsWith("mailto:")) { String email = href.Substring(7, (href.Contains("?") ? href.IndexOf('?') : href.Length) - 7); FoundEmails.AddUniqueItem(email); } else if (href.StartsWith("ftp:")) { return(true); } else if (href.StartsWith("telnet:")) { return(true); } else if (href.StartsWith("ldap:")) { return(true); } else { try { Uri u = new Uri(href); if (u.HostNameType != UriHostNameType.Dns) { return(true); } } catch (UriFormatException) //No es una URI, será un path interno... { if (!href.StartsWith("#")) //Se omiten referencias del tipo #Pais { return(true); } } } } return(false); }
private void analizeLinks(Stream stm) { try { XmlDocument doc = new XmlDocument(); doc.XmlResolver = null; doc.Load(stm); XmlNodeList xnl = doc.GetElementsByTagName("Relationship"); List <string> links = new List <string>(); foreach (XmlNode xn in xnl) { if (xn.Attributes["Type"].Value == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink") { String href = xn.Attributes["Target"].Value; if (href != string.Empty) { if (href.StartsWith("mailto:")) { String email = href.Substring(7, (href.Contains("?") ? href.IndexOf('?') : href.Length) - 7); FoundEmails.AddUniqueItem(email); } else if (href.StartsWith("ftp:")) { if (!links.Contains(href)) { links.Add(href); } } else if (href.StartsWith("telnet:")) { if (!links.Contains(href)) { links.Add(href); } } else if (href.StartsWith("ldap:")) { if (!links.Contains(href)) { links.Add(href); } } else if (href.StartsWith("http:")) { if (!href.EndsWith("/")) // Si la direccion no termina con un slash, se le añade { int cuentaSlash = 0; for (int i = 0; i < href.Length; i++) { if (href[i] == '/') { cuentaSlash++; } } if (cuentaSlash == 2) { href += "/"; } } if (!links.Contains(href)) { links.Add(href); } } else { try { Uri u = new Uri(href); /* * if (u.HostNameType != UriHostNameType.Dns) * { * if (!links.Contains(href)) * links.Add(href); * } */ if (!links.Contains(href)) { links.Add(href); } } catch (UriFormatException) //No es una URI, será un path interno... { if (!href.StartsWith("#")) //Se omiten referencias del tipo #Pais { if (!links.Contains(href)) { links.Add(href); } } } } } } } if (links.Count != 0) { foreach (String link in links) { FoundPaths.AddUniqueItem(PathAnalysis.CleanPath(link), true);//false); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(String.Format("Error searching links ({0}).", e.ToString())); } }
private void analizeFileContent(Stream stm) { try { XmlDocument doc = new XmlDocument(); doc.XmlResolver = null; doc.Load(stm); XmlNodeList xnl = doc.GetElementsByTagName("text:a"); if (xnl != null) { List <String> links = new List <String>(); foreach (XmlNode xn in xnl) { String href = xn.Attributes.GetNamedItem("xlink:href").Value; if (href != string.Empty) { if (href.StartsWith("mailto:")) { String email = href.Substring(7, (href.Contains("?") ? href.IndexOf('?') : href.Length) - 7); FoundEmails.AddUniqueItem(email); } else if (href.StartsWith("ftp:")) { if (!links.Contains(href)) { links.Add(href); } } else if (href.StartsWith("telnet:")) { if (!links.Contains(href)) { links.Add(href); } } else if (href.StartsWith("ldap:")) { if (!links.Contains(href)) { links.Add(href); } } else { try { Uri u = new Uri(href); /* ¿Porque este if, oca?, pueden sacarse nombres sin reoslucion como http://privado/ */ /* * if (u.HostNameType != UriHostNameType.Dns) * { * if (!links.Contains(href)) * links.Add(href); * } */ if (!links.Contains(href)) { links.Add(href); } } catch (UriFormatException) //No es una URI, será un path interno... { if (!href.StartsWith("#")) //Se omiten referencias del tipo #Pais { if (!links.Contains(href)) { links.Add(href); } } } } } } if (links.Count != 0) { foreach (String link in links) { FoundPaths.AddUniqueItem(PathAnalysis.CleanPath(link), true);//false); } } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(String.Format("Error reading file content.xml ({0}).", e.ToString())); } }