Aaaayyyyyyyuuuuuuuuuuuuuudddddddaaaaaaaaaaaaa
Cerrado
CHOCOLATES
-
22 may 2008 a las 19:35
beatle45 Mensajes enviados 628 Fecha de inscripción viernes, 4 de abril de 2008 Estatus Miembro Última intervención martes, 28 de octubre de 2008 - 23 may 2008 a las 16:06
beatle45 Mensajes enviados 628 Fecha de inscripción viernes, 4 de abril de 2008 Estatus Miembro Última intervención martes, 28 de octubre de 2008 - 23 may 2008 a las 16:06
1 respuesta
beatle45
Mensajes enviados
628
Fecha de inscripción
viernes, 4 de abril de 2008
Estatus
Miembro
Última intervención
martes, 28 de octubre de 2008
690
23 may 2008 a las 16:06
23 may 2008 a las 16:06
Hola
aca te mando un codigo
public class TelnetInputStream extends InputStream
{
private static DataInputStream input;
private static DataOutputStream output;
private int width, height;
private String terminal;
// used for replies
private final byte[] reply = { IAC, (byte) 0, (byte) 0 };
public TelnetInputStream(InputStream inInput, OutputStream inOutput)
{
int inWidth=0;
int inHeight=0;
String inTermType=null;
System.out.println("Bien "+inInput+" "+inOutput);
input = (DataInputStream) inInput;
output = (DataOutputStream) inOutput;
width = inWidth;
height = inHeight;
terminal = inTermType;
if ( terminal == null ) terminal = "dumb";
try
{
String resultado;
System.out.println("Resultado: "+read());
System.out.println(LeerDatos(inInput));
inOutput.write("ADMIN".getBytes());
System.out.println("Resultado2: "+read());
System.out.println(LeerDatos(inInput));
inOutput.write("PASS".getBytes());
System.out.println("Resultado2: "+read());
System.out.println(LeerDatos(inInput));
inOutput.write("?".getBytes());
System.out.println("Resultado4: "+read());
System.out.println(LeerDatos(inInput));
inOutput.write("info configure system".getBytes());
System.out.println("Resultado4: "+read());
System.out.println(LeerDatos(inInput));
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String LeerDatos(InputStream sIn) throws IOException
{
String respuesta="";
int c;
byte[] reply = { (byte) 255};
int fin = sIn.available();
//System.out.println("1: "+sIn.available());
//System.out.println("2: "+sIn.hashCode());
for(int i = 0; i<fin;i++)
//String aux=null;
//while((aux = sIn.toString())!=null)
{
try
{
//System.out.println("reply["+i+"]: "+(byte) sIn.read());
c = sIn.read();
char s1 = (char)c;
respuesta += s1;
//System.out.println("Caracter "+s1 +" Fin Caracter");
}
catch(IOException e)
{
System.out.println("No se pudo leer con read() "+e);
}
}
return respuesta;
}
public int read() throws IOException
{
byte b;
b = (byte) input.read();
if ( b != IAC )
{
System.out.println("NOT IAC "+b);
return b;
} // not an IAC, skip.
b = (byte) input.read();
if ( b == IAC ) {System.out.println("TWO IACS isn't IAC "+b);return b;} // two IACs isn't.
if ( b != SB ) // handle command
{
}
return read();
}
public void close() throws IOException
{
input.close();
}
private void write( byte inByte ) throws IOException
{
output.write( inByte );
output.flush();
}
private void write( byte[] inBytes ) throws IOException
{
output.write( inBytes );
output.flush();
}
// iac commands
public static void main(String[] arg)
{
try
{
Socket s = new Socket("172.18.184.85",23);
System.out.println(s);
input = new DataInputStream(s.getInputStream());
output = new DataOutputStream(s.getOutputStream());
TelnetInputStream dir = new TelnetInputStream(input, output);
}
catch(IOException e)
{
System.out.println("Error "+e);
}
}
}
Espero que te sirva
aca te mando un codigo
public class TelnetInputStream extends InputStream
{
private static DataInputStream input;
private static DataOutputStream output;
private int width, height;
private String terminal;
// used for replies
private final byte[] reply = { IAC, (byte) 0, (byte) 0 };
public TelnetInputStream(InputStream inInput, OutputStream inOutput)
{
int inWidth=0;
int inHeight=0;
String inTermType=null;
System.out.println("Bien "+inInput+" "+inOutput);
input = (DataInputStream) inInput;
output = (DataOutputStream) inOutput;
width = inWidth;
height = inHeight;
terminal = inTermType;
if ( terminal == null ) terminal = "dumb";
try
{
String resultado;
System.out.println("Resultado: "+read());
System.out.println(LeerDatos(inInput));
inOutput.write("ADMIN".getBytes());
System.out.println("Resultado2: "+read());
System.out.println(LeerDatos(inInput));
inOutput.write("PASS".getBytes());
System.out.println("Resultado2: "+read());
System.out.println(LeerDatos(inInput));
inOutput.write("?".getBytes());
System.out.println("Resultado4: "+read());
System.out.println(LeerDatos(inInput));
inOutput.write("info configure system".getBytes());
System.out.println("Resultado4: "+read());
System.out.println(LeerDatos(inInput));
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String LeerDatos(InputStream sIn) throws IOException
{
String respuesta="";
int c;
byte[] reply = { (byte) 255};
int fin = sIn.available();
//System.out.println("1: "+sIn.available());
//System.out.println("2: "+sIn.hashCode());
for(int i = 0; i<fin;i++)
//String aux=null;
//while((aux = sIn.toString())!=null)
{
try
{
//System.out.println("reply["+i+"]: "+(byte) sIn.read());
c = sIn.read();
char s1 = (char)c;
respuesta += s1;
//System.out.println("Caracter "+s1 +" Fin Caracter");
}
catch(IOException e)
{
System.out.println("No se pudo leer con read() "+e);
}
}
return respuesta;
}
public int read() throws IOException
{
byte b;
b = (byte) input.read();
if ( b != IAC )
{
System.out.println("NOT IAC "+b);
return b;
} // not an IAC, skip.
b = (byte) input.read();
if ( b == IAC ) {System.out.println("TWO IACS isn't IAC "+b);return b;} // two IACs isn't.
if ( b != SB ) // handle command
{
}
return read();
}
public void close() throws IOException
{
input.close();
}
private void write( byte inByte ) throws IOException
{
output.write( inByte );
output.flush();
}
private void write( byte[] inBytes ) throws IOException
{
output.write( inBytes );
output.flush();
}
// iac commands
public static void main(String[] arg)
{
try
{
Socket s = new Socket("172.18.184.85",23);
System.out.println(s);
input = new DataInputStream(s.getInputStream());
output = new DataOutputStream(s.getOutputStream());
TelnetInputStream dir = new TelnetInputStream(input, output);
}
catch(IOException e)
{
System.out.println("Error "+e);
}
}
}
Espero que te sirva