// Open Dialog to show where is the location on the google map when double click the IP Trace UI. private void mPacketTrace_SelectedDoubleClick(object sender, EventArgs e) { CityResponse IP1, IP2; double IP1_Latitude, IP1_Longitude, IP2_Latitude, IP2_Longitude; string IP_1 = mPacketTrace.SelectedItems[0].SubItems[(int)IP_List_Column.Column_Address_IP1].Text; string IP_2 = mPacketTrace.SelectedItems[0].SubItems[(int)IP_List_Column.Column_Address_IP2].Text; try { IP1 = GeoIP_DatabaseReader.City(IP_1); IP1_Latitude = (double)IP1.Location.Latitude; //緯度 IP1_Longitude = (double)IP1.Location.Longitude; //經度 } catch { IP1_Latitude = 0; IP1_Longitude = 0; } try { IP2 = GeoIP_DatabaseReader.City(IP_2); IP2_Latitude = (double)IP2.Location.Latitude; //緯度 IP2_Longitude = (double)IP2.Location.Longitude; //經度 } catch { IP2_Latitude = 0; IP2_Longitude = 0; } // myBuilder.Append(DstLatitude + "," + DstLongitude); ShowMapForm ShowMap = new ShowMapForm(IP_1, IP_2, IP1_Latitude, IP1_Longitude, IP2_Latitude, IP2_Longitude); // ShowMap.Text = mPacketTrace.SelectedItems[0].SubItems[1].Text + " ( " + myBuilder.ToString() + " ) "; ShowMap.Show(); }
// Find Location and country by IP (Using the tool,GeoIP API) private void FindLocationByIP(IpPacket ipPacket, out string SrcLocation, out string DstLocation) { string SrcIP, DstIP; CityResponse Src, Dst; SrcIP = ipPacket.SourceAddress.ToString(); DstIP = ipPacket.DestinationAddress.ToString(); try { Src = GeoIP_DatabaseReader.City(SrcIP); SrcLocation = Src.Country.ToString() + ((Src.City.ToString() == "") ? "" : (" ( " + Src.City.ToString() + " ) ")); //if( SrcLocation == "" || SrcLocation == " ") // SrcLocation = "Not Found"; } catch { SrcLocation = ""; //SrcLocation = "Not Found"; //byte[] IP = ipPacket.SourceAddress.GetAddressBytes(); //if (IP[0] == 10) //{ // SrcLocation = "Virtual IP"; //} //else if ( IP[0] == 172 ) //{ // if ( IP[1] >= 16 && IP[1] <= 31) // { // SrcLocation = "Virtual IP"; // } //} //else if (IP[0] == 192) //{ // if (IP[1] == 168 ) // { // SrcLocation = "Virtual IP"; // } //} } try { Dst = GeoIP_DatabaseReader.City(DstIP); DstLocation = Dst.Country.ToString() + ((Dst.City.ToString() == "") ? "" : (" ( " + Dst.City.ToString() + " ) ")); //if( DstLocation == "" || DstLocation == " ") // DstLocation = "Not Found"; } catch { DstLocation = ""; //DstLocation = "Not Found"; //byte[] IP = ipPacket.DestinationAddress.GetAddressBytes(); //if (IP[0] == 10) //{ // DstLocation = "Virtual IP"; //} //else if (IP[0] == 172) //{ // if (IP[1] >= 16 && IP[1] <= 31) // { // DstLocation = "Virtual IP"; // } //} //else if (IP[0] == 192) //{ // if (IP[1] == 168) // { // DstLocation = "Virtual IP"; // } //} } }