Windows Azure Cloud Storage ermöglicht es Ihnen bereits ab 0,10€ pro GB/Monat die Vorteile der Cloud zu nutzen.
Willkommen bei dotnet-snippets.de! Snippet hinzufügen Login Registrieren
Snippets in der Datenbank: 1551 | Anzahl registrierter User: 1841 | Besucher online: 1
Hauptmenü
Home
Top Ten
Zufälliger Snippet
FAQs
.NET Community
dotnet-forum.de
dotnet-kicks.de
Social

RSS Feeds
Rss Alle Snippets
Rss C#
Rss VB.NET
Rss C++
Rss ASP.NET
Partner
Member of Microsoft Community Leader/Insider Program (CLIP)

GeoLocation einer IP Adresse ermitteln


Autor: Jan Welker
Sprache: C#
Bewertung:
noch nicht bewertet
Anzahl der Aufrufe: 5252
  
Kick it on dotnet-kicks.de  

Beschreibung:

Der Dienst ipinfodb.com bietet eine kostenlose Lokalisierung der übergebenen IP Adresse an. Dieser Snippet zeigt, wie die Informationen mit .NET abgerufen werden können. Exceptionhandling ist nicht implementiert.

Abgelegt unter: GeoLocation, IP, IP Adresse, Longitude, Latitude.



C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Xml.Linq;
 
namespace IpLoc
{
    internal class IpInfo
    {
        public IpInformation GetIpInformation(string ip)
        {
            WebClient webClient = new WebClient();
            webClient.Encoding = Encoding.UTF8;
            XDocument xDocument = XDocument.Parse(webClient.DownloadString(string.Format("http://ipinfodb.com/ip_query.php?ip={0}&timezone=false", ip)));
            IpInformation ipInformation = new IpInformation();
 
            ipInformation.Ip = xDocument.Elements().Select(a => a.Element("Ip").Value).FirstOrDefault();
            ipInformation.CountryCode = xDocument.Elements().Select(a => a.Element("CountryCode").Value).FirstOrDefault();
            ipInformation.CountryName = HttpUtility.HtmlDecode(xDocument.Elements().Select(a => a.Element("CountryName").Value).FirstOrDefault());
            ipInformation.RegionCode = xDocument.Elements().Select(a => a.Element("RegionCode").Value).FirstOrDefault();
            ipInformation.RegionName = HttpUtility.HtmlDecode(xDocument.Elements().Select(a => a.Element("RegionName").Value).FirstOrDefault());
            ipInformation.City = HttpUtility.HtmlDecode(xDocument.Elements().Select(a => a.Element("City").Value).FirstOrDefault());
            ipInformation.ZipPostalCode = xDocument.Elements().Select(a => a.Element("ZipPostalCode").Value).FirstOrDefault();
            ipInformation.Latitude = xDocument.Elements().Select(a => a.Element("Latitude").Value).FirstOrDefault();
            ipInformation.Longitude = xDocument.Elements().Select(a => a.Element("Longitude").Value).FirstOrDefault();
 
            return ipInformation;
        }
 
        #region Nested type: IpInformation
 
        public class IpInformation
        {
            public string Ip { get; set; }
            public string CountryCode { get; set; }
            public string CountryName { get; set; }
            public string RegionCode { get; set; }
            public string RegionName { get; set; }
            public string City { get; set; }
            public string ZipPostalCode { get; set; }
            public string Latitude { get; set; }
            public string Longitude { get; set; }
        }
 
        #endregion
    }
}

Sie haben Fragen zu diesem Snippet oder brauchen Hilfe bei der .NET Entwicklung?
Freundliche und kompetente Entwickler helfen Ihnen gern weiter im Forum für .NET Entwicklung.



Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)



schlecht sehr gut
1 2 3 4 5 6 7 8 9 10
Nur angemeldete User können Snippets bewerten.