public static void Main(string[] argv) { if (argv.Length == 1) { ip2country ic = new ip2country( "ip2cntry.dat" ); TimeSpan span; DateTime end; DateTime start = DateTime.Now; int countryidx = ic.lookup( argv[0] ); switch ( countryidx ) { case -1: Console.WriteLine( "{0} is not in the database", argv[0] ); break; case -2: Console.WriteLine( "{0} doesn't seem to be a valid IP number.", argv[0] ); break; case -3: Console.WriteLine( "ip2cntry.dat is not a valid database" ); break; default: String country = ic.countryCode( countryidx ); end = DateTime.Now; span = new TimeSpan( end.Ticks - start.Ticks ); Console.WriteLine( "{0} is in {1} - took {2} ms", argv[0], country, Math.Round(span.TotalMilliseconds) ); break; } } else { Console.WriteLine( "Usage: ip2c <IP address>" ); } }
void CreatedFormLoad(object sender, System.EventArgs e) { int n; using ( StreamReader sr = new StreamReader( "Servers.lst" )) { String line; while ( ( line = sr.ReadLine() ) != null ) { //if ( !serverlist.Items.Contains( line ) ) serverlist.Items.Add( line ); } n = serverlist.Items.Count; ips = new String[ n ]; serverlist.Items.CopyTo( ips, 0 ); listinfo.Text = "There are " + n.ToString() + " unique IPs in the list."; sr.Close(); } /* using ( StreamWriter sw = new StreamWriter( "Servers.lst" )) { for ( i = 0; i < n; i++ ) sw.WriteLine( ips[ i ] ); sw.Close(); } */ bool cacheIt = true; if (argv.Length == 1) if (argv[0] == "/nocache") cacheIt = false; ic = new ip2country( "ip2cntry.dat", cacheIt ); }