Presentation is loading. Please wait.

Presentation is loading. Please wait.

M2-Internet 1 DNS: Domain Name System People: many identifiers: SSN, name, passport # Internet hosts, routers: IP address (32 bit) - used for addressing.

Similar presentations


Presentation on theme: "M2-Internet 1 DNS: Domain Name System People: many identifiers: SSN, name, passport # Internet hosts, routers: IP address (32 bit) - used for addressing."— Presentation transcript:

1 M2-Internet 1 DNS: Domain Name System People: many identifiers: SSN, name, passport # Internet hosts, routers: IP address (32 bit) - used for addressing datagrams name, e.g., ww.yahoo.com - used by humans Q: map between IP addresses and name ? Domain Name System: r distributed database implemented in hierarchy of many name servers r application-layer protocol host, routers, name servers to communicate to resolve names (address/name translation) note: core Internet function, implemented as application-layer protocol complexity at networks edge H. Fauconnier

2 M2-Internet 2 DNS Why not centralize DNS? r single point of failure r traffic volume r distant centralized database r maintenance doesnt scale! DNS services r hostname to IP address translation r host aliasing Canonical, alias names r mail server aliasing r load distribution replicated Web servers: set of IP addresses for one canonical name H. Fauconnier

3 M2-Internet 3 Root DNS Servers com DNS servers org DNS serversedu DNS servers poly.edu DNS servers umass.edu DNS servers yahoo.com DNS servers amazon.com DNS servers pbs.org DNS servers Distributed, Hierarchical Database Client wants IP for www.amazon.com; 1 st approx: r client queries a root server to find com DNS server r client queries com DNS server to get amazon.com DNS server r client queries amazon.com DNS server to get IP address for www.amazon.com H. Fauconnier

4 M2-Internet 4 DNS: Root name servers r contacted by local name server that can not resolve name r root name server: contacts authoritative name server if name mapping not known gets mapping returns mapping to local name server 13 root name servers worldwide b USC-ISI Marina del Rey, CA l ICANN Los Angeles, CA e NASA Mt View, CA f Internet Software C. Palo Alto, CA (and 36 other locations) i Autonomica, Stockholm (plus 28 other locations) k RIPE London (also 16 other locations) m WIDE Tokyo (also Seoul, Paris, SF) a Verisign, Dulles, VA c Cogent, Herndon, VA (also LA) d U Maryland College Park, MD g US DoD Vienna, VA h ARL Aberdeen, MD j Verisign, ( 21 locations) H. Fauconnier

5 M2-Internet 5 TLD and Authoritative Servers r Top-level domain (TLD) servers: responsible for com, org, net, edu, etc, and all top-level country domains uk, fr, ca, jp. Network Solutions maintains servers for com TLD Educause for edu TLD r Authoritative DNS servers: organizations DNS servers, providing authoritative hostname to IP mappings for organizations servers (e.g., Web, mail). can be maintained by organization or service provider H. Fauconnier

6 M2-Internet 6 Local Name Server r does not strictly belong to hierarchy r each ISP (residential ISP, company, university) has one. also called default name server r when host makes DNS query, query is sent to its local DNS server acts as proxy, forwards query into hierarchy H. Fauconnier

7 M2-Internet 7 requesting host cis.poly.edu gaia.cs.umass.edu root DNS server local DNS server dns.poly.edu 1 2 3 4 5 6 authoritative DNS server dns.cs.umass.edu 7 8 TLD DNS server DNS name resolution example r Host at cis.poly.edu wants IP address for gaia.cs.umass.edu iterated query: rcontacted server replies with name of server to contact rI dont know this name, but ask this server H. Fauconnier

8 M2-Internet 8 requesting host cis.poly.edu gaia.cs.umass.edu root DNS server local DNS server dns.poly.edu 1 2 4 5 6 authoritative DNS server dns.cs.umass.edu 7 8 TLD DNS server 3 recursive query: rputs burden of name resolution on contacted name server rheavy load? DNS name resolution example H. Fauconnier

9 M2-Internet 9 DNS: caching and updating records r once (any) name server learns mapping, it caches mapping cache entries timeout (disappear) after some time TLD servers typically cached in local name servers Thus root name servers not often visited r update/notify mechanisms under design by IETF RFC 2136 http://www.ietf.org/html.charters/dnsind-charter.html H. Fauconnier

10 M2-Internet 10 DNS records DNS: distributed db storing resource records (RR) r Type=NS name is domain (e.g. foo.com) value is hostname of authoritative name server for this domain RR format: (name, value, type, ttl) rType=A name is hostname value is IP address rType=CNAME name is alias name for some canonical (the real) name www.ibm.com is really servereast.backup2.ibm.com value is canonical name rType=MX value is name of mailserver associated with name H. Fauconnier

11 M2-Internet 11 DNS protocol, messages DNS protocol : query and reply messages, both with same message format msg header ridentification: 16 bit # for query, reply to query uses same # rflags: query or reply recursion desired recursion available reply is authoritative H. Fauconnier

12 M2-Internet 12 DNS protocol, messages Name, type fields for a query RRs in response to query records for authoritative servers additional helpful info that may be used H. Fauconnier

13 M2-Internet 13 Inserting records into DNS r example: new startup Network Utopia r register name networkuptopia.com at DNS registrar (e.g., Network Solutions) provide names, IP addresses of authoritative name server (primary and secondary) registrar inserts two RRs into com TLD server: (networkutopia.com, dns1.networkutopia.com, NS) (dns1.networkutopia.com, 212.212.212.1, A) r create authoritative server Type A record for www.networkuptopia.com; Type MX record for networkutopia.com r How do people get IP address of your Web site? H. Fauconnier

14 Quelques compléments Java réseaux 14 H. Fauconnier M2-Internet

15 Sommaire URL et URI html et swing URLconnections URLStreamHandler URLStreamHandlerFactory ContentHandler ContentHandlerFactory 15 H. Fauconnier M2-Internet

16 URL la classe URL permet d'utiliser les URLURL les classes URLDecoder et URLEncoder permettent de traiter les formulaires HTMLURLDecoderURLEncoder Une URI (Uniform ressource Identifier), est une sorte de généralisation des URL qui inclut de Uniform Resource Location (URL) mais aussi de Uniform Ressource Names (URN)URI exemples tel:1-800-9988-9938 http://www.xml.comp/pub/stax.html#id =_hdbc (la classe URLConnection sera décrite plus loin) 16 H. Fauconnier M2-Internet

17 URI URI: URL (location) http://java.sun.com/j2se/1.3/docs/guide/collections/de signfaq.html#28 ou URN (name): mailto:java-net@java.sun.com Syntaxe: Général: [scheme:]scheme-specific-part[#fragment] Hiérarchique: [scheme:][//authority][path][?query][#fragment] Authorité: [user-info@]host[:port] H. Fauconnier M2-Internet 1-17

18 URL http://www.bib.org:80/javafaq/book/index.html?i sbn=56888#toc ftp://anonymous:anonymous@ftp.bib.org/c%3a/stuf f protocol port authority chemin référence requête user 18 H. Fauconnier M2-Internet

19 Construire une URLURL public URL(String url) throws MalformedURLException public URL(String protocol, String hostname, String file) throws MalformedURLException public URL(String protocol, String host, int port, String file) throws MalformedURLException public URL(URL base, String relative) throws MalformedURLException 19 H. Fauconnier M2-Internet

20 Remarques tous les protocoles ne sont pas compris par la machine virtuelle… exception MalFormedURLException 20 H. Fauconnier M2-Internet

21 Exemple: Quels protocoles? import java.net.*; public class ProtocolTester { public static void main(String[] args) { testProtocol("http://www.adc.org"); testProtocol("https://www.amazon.com/exec/obidos/order2/"); testProtocol("ftp://metalab.unc.edu/pub/languages/java/javafaq/"); testProtocol("mailto:elharo@metalab.unc.edu"); testProtocol("telnet://dibner.poly.edu/"); testProtocol("file:///etc/passwd"); testProtocol("gopher://gopher.anc.org.za/"); testProtocol( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress"); testProtocol( "jar:http://cafeaulait.org/books/javaio/ioexamples/javaio.jar!" +"/com/macfaq/io/StreamCopier.class"); testProtocol("nfs://utopia.poly.edu/usr/tmp/"); testProtocol("jdbc:mysql://luna.metalab.unc.edu:3306/NEWS"); testProtocol("rmi://metalab.unc.edu/RenderEngine"); testProtocol("doc:/UsersGuide/release.html"); testProtocol("netdoc:/UsersGuide/release.html"); testProtocol("systemresource://www.adc.org/+/index.html"); testProtocol("verbatim:http://www.adc.org/"); } 21 H. Fauconnier M2-Internet

22 Quels protocoles (suite) private static void testProtocol(String url) { try { URL u = new URL(url); System.out.println(u.getProtocol() + " is supported"); } catch (MalformedURLException ex) { String protocol = url.substring(0,url.indexOf(':')); System.out.println(protocol + " is not supported"); } } http is supported https is supported ftp is supported mailto is supported telnet is not supported file is supported gopher is supported ldap is not supported jar is supported nfs is not supported jdbc is not supported rmi is not supported doc is supported netdoc is supported systemresource is supported verbatim is supported 22 H. Fauconnier M2-Internet

23 Décomposer l'url public static void decomposeURL(String st) { try{ URL u = new URL(st); System.out.println("URL :" + u); System.out.println("Protocole : " + u.getProtocol( )); System.out.println("UserInfo :" + u.getUserInfo( )); String host = u.getHost( ); if (host != null) { int atSign = host.indexOf('@'); if (atSign != -1) host = host.substring(atSign+1); System.out.println("hôte " + host); } else { System.out.println("hôte null."); } 23 H. Fauconnier M2-Internet

24 suite System.out.println("Port :" + u.getPort( )); System.out.println("Path : " + u.getPath( )); System.out.println("Ref : " + u.getRef( )); System.out.println("Query: " + u.getQuery( )); } catch (MalformedURLException ex) {System.err.println(st + " URL malformée"); } } 24 H. Fauconnier M2-Internet

25 Résultat http://www.bib.org:80/javafaq/book/index.html?isb n=56888#toc URL :http://www.bib.org:80/javafaq/book/index.html? isbn=56888#toc Protocole : http UserInfo :null hôte www.bib.org Port :80 Path : /javafaq/book/index.html Ref : toc Query: isbn=56888 25 H. Fauconnier M2-Internet

26 Obtenir des données public InputStream openStream( ) throws IOException public URLConnection openConnection( ) throws IOException public URLConnection openConnection(Proxy proxy) throws IOException public Object getContent( ) throws IOException public Object getContent(Class[] classes) throws IOException 26 H. Fauconnier M2-Internet

27 Charger le contenu d'une URL public static void chargerFichier(String url) { try { URL u = new URL(url); InputStream in = u.openStream(); in = new BufferedInputStream(in); Reader r = new InputStreamReader(in); int c; while ((c = r.read()) != -1) { System.out.print((char) c); } } catch (MalformedURLException ex) { System.err.println(url + " mauvaise URL"); } catch (IOException e) { System.err.println(e + " problème de lecture url " + url); } 27 H. Fauconnier M2-Internet

28 Type du contenu public static void typeObjetURL(String st) { try { URL u = new URL(st); try { Object o = u.getContent(); System.out.println("L'objet est un " + o.getClass().getName()); } catch (IOException ex) {System.err.println(ex);} } catch (MalformedURLException ex) { System.err.println(st + " URL malformée"); } http://www.liafa.jussieu.fr L'objet est un sun.net.www.protocol.http.HttpURLConnection$HttpInputStream 28 H. Fauconnier M2-Internet

29 Et encore URLEncoder URLDecoder 29 H. Fauconnier M2-Internet

30 URLEncode: ExempleExemple public class QueryString { private StringBuffer query = new StringBuffer(); public QueryString(String name, String value) { encode(name, value); } public synchronized void add(String name, String value) { query.append('&'); encode(name, value); } private synchronized void encode(String name, String value){ try { query.append(URLEncoder.encode(name, "UTF-8")); query.append('='); query.append(URLEncoder.encode(value, "UTF-8")); } catch (UnsupportedEncodingException ex) { throw new RuntimeException("??"); } //... 30 H. Fauconnier M2-Internet

31 Exemple (suite) /… public String getQuery() { return query.toString(); } public String toString() { return getQuery(); } 31 H. Fauconnier M2-Internet

32 Authentication Classe (abstraite) AuthenticatorAuthenticator PasswordAuthentication représente un couple password + user PasswordAuthentication Méthode getPasswordAuthentication() à redéfinir pour obtenir un PasswordAuthenitcation Méthode setDefault(Authenticator) définit l'Authenticator pour le système C'est à lui que s'adressera le système à chaque fois que nécessaire 32 H. Fauconnier M2-Internet

33 Pour apache: Fichier.htaccess: (il faut aussi un AllowOverride AuthConfig dans httpd.conf ) AuthType Basic AuthName "restreint" AuthUserFile /Users/hf/Sites/.psswd Require user hf.psswd est le fichier des mots de passe htpasswd –c /Users/hf/Sites/.passwd hf 33 H. Fauconnier M2-Internet

34 Exemple 34 H. Fauconnier M2-Internet


Download ppt "M2-Internet 1 DNS: Domain Name System People: many identifiers: SSN, name, passport # Internet hosts, routers: IP address (32 bit) - used for addressing."

Similar presentations


Ads by Google