Two Laptop Bag*
The moose likes Sockets and Internet Protocols and the fly likes Connecting to a router Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Connecting to a router" Watch "Connecting to a router" New topic
Author

Connecting to a router

ahmed abobakr
Greenhorn

Joined: Jul 14, 2011
Posts: 3
Hi
I want to make a program to connect to a router using Http protocol or Telnet protocol.
I tried running a command prompt on my PC and connecting to the router using telnet commands i used the Process class but i failed

Thank you in advance
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Welcome to the Ranch!

java telnet leads to several Telnet libraries. Surprisingly, Apache Commons Net isn't found on the first two pages, so I thought I'd mention it explicitly.

HTTP is probably going to be more difficult as it will certainly involve a bit more complex requests. HttpClient can be a great help.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
ahmed abobakr
Greenhorn

Joined: Jul 14, 2011
Posts: 3
thank you Rob Spoor


how can i send multiple commands to command prompt?

I tried this code. what the error here?

this program didn't have syntax errors.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Please don't use such a large font. I've had to remove the formatting on both of your posts already. Also, UseCodeTags from now on. See how much easier your code is to read.

Why didn't you use a Telnet library like I suggested?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Is the command-line Telnet client on your system really called "telent"?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The Windows telnet client is a GUI client that doesn't take commands on the command line; something tells me he's just using that stock client, anyway.


[Jess in Action][AskingGoodQuestions]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41149
    
  45
Does the router really accept Telnet requests?

One issue to be aware of is Don't println to a Socket, which the code is doing by using readLine.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

There's a slight difference. readLine is able to handle \r, \n and \r\n as line breaks. It did (does?) have a bug that if the stream ends with a \r without a \n after it, readLine would block.
ahmed abobakr
Greenhorn

Joined: Jul 14, 2011
Posts: 3
Thank you for helping me

I think i found the solution to my problem here


but i don't know how can i press the carriage return?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

A carriage return is just the character '\r'. You can include that in Strings as you would any other character.
 
Consider Paul's rocket mass heater.
 
subject: Connecting to a router
 
Similar Threads
Accessing cisco router
router configuration
Passed II/III with 95%
port forwarding-can't open the routers web based configuration page
how to connect router using java application