/// <summary> /// Gets the version of the running tor application. /// </summary> /// <returns>A <see cref="Version"/> object instance containing the version.</returns> private Version PropertyGetVersion() { GetInfoCommand command = new GetInfoCommand("version"); GetInfoResponse response = command.Dispatch(client); if (!response.Success) { return(new Version()); } Regex pattern = new Regex(@"(?<major>\d{1,})\.(?<minor>\d{1,})\.(?<build>\d{1,})\.(?<revision>\d{1,})(?:$|\s)"); Match match = pattern.Match(response.Values[0]); if (match.Success) { return(new Version( Convert.ToInt32(match.Groups["major"].Value), Convert.ToInt32(match.Groups["minor"].Value), Convert.ToInt32(match.Groups["build"].Value), Convert.ToInt32(match.Groups["revision"].Value) )); } return(new Version()); }
/// <summary> /// Gets a country code for a router within the tor network. This method will not work unless a <c>geoip</c> and/or <c>geoip6</c> file has been supplied. /// </summary> /// <param name="router">The router to retrieve the country code for.</param> /// <returns>A <see cref="System.String"/> containing the country code; otherwise, <c>null</c> if the country code could not be resolved.</returns> public string GetCountryCode(Router router) { if (router == null) { throw new ArgumentNullException("router"); } string address = router.IPAddress.ToString(); GetInfoCommand command = new GetInfoCommand(string.Format("ip-to-country/{0}", address)); GetInfoResponse response = command.Dispatch(client); if (response.Success) { string[] values = response.Values[0].Split(new[] { '=' }, 2); if (values.Length == 2) { return(values[1].Trim()); } return(values[0].Trim().ToUpper()); } return(null); }
/// <summary> /// Gets an approximation of the total bytes uploaded by the tor software. /// </summary> /// <returns>A <see cref="Bytes"/> object instance containing the estimated number of bytes.</returns> private Bytes PropertyGetTotalBytesUploaded() { GetInfoCommand command = new GetInfoCommand("traffic/written"); GetInfoResponse response = command.Dispatch(client); if (!response.Success) { return(Bytes.Empty); } double value; if (!double.TryParse(response.Values[0], out value)) { return(Bytes.Empty); } return(new Bytes(value).Normalize()); }
/// <summary> /// Gets a value indicating whether the tor software service is dormant. /// </summary> /// <returns><c>true</c> if the tor software service is dormant; otherwise, <c>false</c>.</returns> private bool PropertyGetIsDormant() { GetInfoCommand command = new GetInfoCommand("dormant"); GetInfoResponse response = command.Dispatch(client); if (!response.Success) { return(false); } int value; if (!int.TryParse(response.Values[0], out value)) { return(false); } return(value != 0); }