Pagina 1 di 1
dns e java
Inviato: martedì 10 giugno 2008, 23:40
da thor_cthulhu
salve a tutti,
devo realizzare un programmino in java.. ma il problema non ce l'ho tanto in java...
Nel programmino ho l'email di un utente, e devo spedire tale emali nel suo server di posta smtp... il problema è che non riesco ad ottenere l'indirizzo ip di un server smtp dato semplicemente la sua estensione es:
se scrivo sulla riga di comando: nslookup fastweb.it ... esso risponde con un indirizzo ip equivalente al server web,
solo se scrivo smtp.fastweb.it ottengo il valore giusto.
Il problema è ke non a tutti i server basta aggiungere smtp, e quindi come faccio a ottenere l'ip di un qualsiasi server smtp??
Mi salvate la vita se riuscite a rispondere a questa domanda, quindi ringrazio anticipatamente (b2b)
Re: dns e java
Inviato: martedì 10 giugno 2008, 23:43
da pieddu
3 post identici..... mai visto

Re: dns e java
Inviato: martedì 10 giugno 2008, 23:45
da thor_cthulhu
pieddu ha scritto:
3 post identici..... mai visto
scusa...ma è urgente ecco perchè.. purtroppo su internet non trovo soluzione
Re: dns e java
Inviato: martedì 10 giugno 2008, 23:47
da pieddu
cmq, magari l'ip è lo stesso del server web, solo che cambia la porta.....

Re: dns e java
Inviato: mercoledì 11 giugno 2008, 0:34
da thor_cthulhu
pieddu ha scritto:
cmq, magari l'ip è lo stesso del server web, solo che cambia la porta.....
magari fosse cosi...hanno quasi tutti ip diversi
Re: dns e java
Inviato: mercoledì 11 giugno 2008, 1:12
da Volans
@thor_cthulhu:
avere fretta non è un motivo per cui sia possibile inserire più messaggi identici. Il crossposting è vietato dal Regolamento in ogni caso, per cui ho chiuso e spostato in Quarantena gli altri due topic e ti consiglio di leggere attentamente il nostro Regolamento.
Re: dns e java
Inviato: mercoledì 11 giugno 2008, 13:46
da ryuujin
thor_cthulhu ha scritto:
Il problema è ke non a tutti i server basta aggiungere smtp, e quindi come faccio a ottenere l'ip di un qualsiasi server smtp??
devi fare una query al record mx del dns.
ad esempio con dig:
Codice: Seleziona tutto
dig fastweb.it mx
fastweb.it. 3596 IN MX 15 smail4.fastweb.it.
fastweb.it. 3596 IN MX 20 relay2.fastweb.it.
fastweb.it. 3596 IN MX 15 smail3.fastweb.it.
dig tin.it mx
tin.it. 1105 IN MX 10 smtp.tin.it.
r.
Re: dns e java
Inviato: giovedì 12 giugno 2008, 21:00
da thor_cthulhu
ryuujin ha scritto:
thor_cthulhu ha scritto:
Il problema è ke non a tutti i server basta aggiungere smtp, e quindi come faccio a ottenere l'ip di un qualsiasi server smtp??
devi fare una query al record mx del dns.
ad esempio con dig:
Codice: Seleziona tutto
dig fastweb.it mx
fastweb.it. 3596 IN MX 15 smail4.fastweb.it.
fastweb.it. 3596 IN MX 20 relay2.fastweb.it.
fastweb.it. 3596 IN MX 15 smail3.fastweb.it.
dig tin.it mx
tin.it. 1105 IN MX 10 smtp.tin.it.
r.
si, ma in java come faccio???
Re: dns e java
Inviato: venerdì 13 giugno 2008, 14:14
da ryuujin
thor_cthulhu ha scritto:
si, ma in java come faccio???
butta un occhio qua:
http://www.dnsjava.org/
puoi scaricarti il jar ed usarlo nel tuo progetto.
Per ricavare il record MX:
Codice: Seleziona tutto
Record [] records = new Lookup("dnsjava.org", Type.MX).run();
for (int i = 0; i < records.length; i++) {
MXRecord mx = (MXRecord) records[i];
System.out.println("Host " + mx.getTarget() + " has preference ", mx.getPriority());
}
Se vuoi una cosa piu' sbrigativa:
Codice: Seleziona tutto
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.directory.*;
public class MXLookup {
public static void main( String args[] ) {
if( args.length == 0 ) {
System.err.println( "Usage: MXLookup host [...]" );
System.exit( 99 );
}
for( int i = 0; i < args.length; i++ ) {
try {
System.out.println( args[i] + " has " +
doLookup( args[i] ) + " mail servers" );
}
catch( Exception e ) {
System.out.println(args[i] + " : " + e.getMessage());
}
}
}
static int doLookup( String hostName ) throws NamingException {
Hashtable env = new Hashtable();
env.put("java.naming.factory.initial",
"com.sun.jndi.dns.DnsContextFactory");
DirContext ictx = new InitialDirContext( env );
Attributes attrs =
ictx.getAttributes( hostName, new String[] { "MX" });
Attribute attr = attrs.get( "MX" );
if( attr == null ) return( 0 );
return( attr.size() );
}
}
r.
PS: basta che cerchi con google. Ad esempio: get mx record java
Re: dns e java
Inviato: sabato 14 giugno 2008, 20:34
da thor_cthulhu
ryuujin ha scritto:
thor_cthulhu ha scritto:
si, ma in java come faccio???
butta un occhio qua:
http://www.dnsjava.org/
puoi scaricarti il jar ed usarlo nel tuo progetto.
Per ricavare il record MX:
Codice: Seleziona tutto
Record [] records = new Lookup("dnsjava.org", Type.MX).run();
for (int i = 0; i < records.length; i++) {
MXRecord mx = (MXRecord) records[i];
System.out.println("Host " + mx.getTarget() + " has preference ", mx.getPriority());
}
Se vuoi una cosa piu' sbrigativa:
Codice: Seleziona tutto
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.directory.*;
public class MXLookup {
public static void main( String args[] ) {
if( args.length == 0 ) {
System.err.println( "Usage: MXLookup host [...]" );
System.exit( 99 );
}
for( int i = 0; i < args.length; i++ ) {
try {
System.out.println( args[i] + " has " +
doLookup( args[i] ) + " mail servers" );
}
catch( Exception e ) {
System.out.println(args[i] + " : " + e.getMessage());
}
}
}
static int doLookup( String hostName ) throws NamingException {
Hashtable env = new Hashtable();
env.put("java.naming.factory.initial",
"com.sun.jndi.dns.DnsContextFactory");
DirContext ictx = new InitialDirContext( env );
Attributes attrs =
ictx.getAttributes( hostName, new String[] { "MX" });
Attribute attr = attrs.get( "MX" );
if( attr == null ) return( 0 );
return( attr.size() );
}
}
r.
PS: basta che cerchi con google. Ad esempio: get mx record java
grazie mille