using System.Net; namespace VisualTraceRoute.Net { /// /// Trace route hop. /// public class Hop { private IPAddress _address; private int _hop; private long _roundTrip; /// /// Gets the Internet address in standard notation. /// public string Address { get { return this._address.ToString(); } } /// /// Gets the hop count. /// public int HopCount { get { return this._hop; } } /// /// Gets the Internet address host name. /// public string HostName { get { string hostName; try { hostName = Dns.GetHostEntry(this._address).HostName; } catch { hostName = this._address.ToString(); } return hostName; } } /// /// Gets the total round trip time (in milliseconds). /// public long RoundTrip { get { return this._roundTrip; } } /// /// Initializes a new instance of the Hop class. /// /// Internet address. /// Round trip time in milliseconds. /// Hop count. public Hop(IPAddress Address, long RoundTrip, int Hop) { this._address = Address; this._hop = Hop; this._roundTrip = RoundTrip; } /// /// Write the trace route reply in standard output format. /// /// Trace hop. public override string ToString() { return this.ToString(false); } /// /// Write the trace route reply in standard output format. /// /// A value indicating whether to resolve the hostname of the reply. /// Trace route hop. public string ToString(bool ResolveHostNames) { return string.Format ( "{0}\t{1}ms\t{2}{3}", this._hop.ToString(), this._roundTrip.ToString(), ResolveHostNames ? string.Format("[{0}] ", this.HostName) : string.Empty, this._address.ToString() ); } } }