What method could I use to login to a Cisco or Juniper routers? I know I can use telnet to make a connection to the router itself but I am not aware of an API or anything that allows me to login non-interactively. So how could I do this?
Are there any libraries I can use to achieve this?
I have seen people use scripts that implement things like expect to know when to send the username and the password. But that is for shell scripting. How can I do this in java? I would prefer to keep strictly in java too.
The goal of this is allow a java program login into a router so I can query the router for interface states and execute commands on the router.
Any ideas?
You need to use some Java library for doing the same. http://www.pitman.co.za/projects/jssh/ is a good Java SSH client. http://commons.apache.org/proper/commons-net/ has a good telnet implementation
As far as extracting information, you should be able to do it by using SNMP to query the router. Pretty much everything is available over SNMP. Now, as far as command execution, there are SNMP set commands used to "write" information to a router, but you will need to look into that more carefully as I doubt the full command set can be replaced with SNMP set commands.
For Cisco, find out what the IOS image filename is for your device, then you can get the MIB file here: http://tools.cisco.com/Support/SNMP/do/MIBSupport.do?local=en&step=3. Review the MIB file and you will see what is available via SNMP for that device.
You should be able to do something similar for Juniper on their site.
Now, I don't know much about Java, but I do know that there are SNMP libraries available for it (like http://www.snmp4j.org/ ).
With that you will not need to worry about logging into the router, or about any interactive stuff.
Note that, in the case of Cisco, it's common to connect using a serial port on a PC directly into the service port on the router. This connection uses a programming protocol called IOS.
The easiest way to utilize this is with a programming language called expect. This name describes the language in that you expect to get a prompt from the port and then you respond. Sending that message (your response), you expect to get another response, to which you respond, ad completum - my term ;)
Note that this cable is proprietary to Cisco, I'm sure there are pin-outs available though.
Finally, it would be possible to emulate this program on java, via a serial port library.
Related
I am working on an application where the app should able to read/fetch the emails from a smtp server. The problem is the ports may differ in different environment. Is there any way to connect to smtp/pop (microsoft exchage) server without knowing the port. Any information might be helpful because of I am new to this javamail api's.
There are standard ports for these services, which JavaMail uses by default. It's relatively rare that one of these services will use a non-standard port. But you do need to know whether the service requires SSL or not, and there are two standard ports used for SMTP. You could easily write code that tries all the common ports and you would probably cover 99.99% of the cases.
I don't think that would be possible. Each port serves a different purpose.
What you can do is read your port number from an external property file, so that your code becomes environment independent, and then you just have to change the value in your property file which placed outside your deployed war/jar
This way, your port no value could be environment specific without having to change your code.
I am very new to jxfs things. I have a requirement to call jxfs server which is in cloud server from the jxfs client which is in ATM environment.. How can i call?.. I need to call this one through the Jxfs RMI concept. It would be appreciated one if any example code is available. If atleast you are having code for calling from jxfs server to jxfs client, please post it.
Thanks in advance guys.
One of the interesting things about J/XFS and remote device access (based on RMI) is that it is just matter of configuration.
You need to configure a J/XFS repository in order to handle a remote device (basically set 'remoteAccess' to true).
Then accessing these devices from the programming point of view is just the same as they were local devices.
Architecture is explained here: ftp://ftp.cencenelec.eu/CWA/CEN/WS-J-XFS/cwa14923/cwa14923-01-2004-May.pdf
Details, when programming may differ depending on the J/XFS implementation you are using.
Trying to answer your question below:
Whenever you want to access a device remotely in J/XFS, RMI is used. You need to make the following setup:
On a server (should be accessible) you need to start a JxfsServer. The JxfsServer will use a Read.repository
whith all the ATM's and devices configured on them as workstations, with the right IP addresses.
On the ATM, you need to install:
J/XFS libs
J/XFS device services for the devices on the ATM
Setup the DSstarter:
Will use the SpecificDeviceManagerRMI connecting to the JxfsServer you started before.
On your server (cloud) wherever you are going to use the J/XFS client you can get the remote controls by performing
the J/XFS initialization as follows:
jxfsDM_ = JxfsDeviceManager.getReference();
jxfsDM_.initialize("com.jxfs.forum.communication.rmi.SpecificDeviceManagerRMI,<atmWorkstation>,AppTest,2006;<jxfsserverhostname>,");
Then you can get the remote device controls with getDevice(...), and start using them as if they were local devices.
Please, note that handling RMI ports can be tricky, specially in a secured environment as ATM network. Make sure all the ports you need are open.
I want to connect my android application to an applet which is running on my pc on Google chrome on Wi-fi.. where my phone works as a wi-fi hotspot and pc as the connected device. I want the connection to work uniquely as I want commands to be passed from my application to the specific applet, on the execution of which my applet does specific tasks. Please tell me the APIs which I can look in both Java and Android or the technology I have to use to make it work..
You need to use any program, such as wamp server, to make your computer to be a localserver. It will install PHP 5, MySQL and Apache. In other hand, you will also need a little bit of knowledge in Php language to create you own web services.
Another thing you need to be aware is that to handle you connection between server and device (and by this I mean which IP you are going to use) you will have a little headache; but first things first..break your problem in little parts thus will be easier to solve them.
I recommend this tutorial.
I think the simple way to connect these two softwares is using UDP.
It is fast, it is easy to program but it is generally unreliable according to TCP. But it is already local network. I dont think that is a case you need to take care in your local wifi network.
So take a look at this tutorial http://tutorials.jenkov.com/java-networking/udp-datagram-sockets.html
There are other ways like https://www.alljoyn.org/. It has more functinality but more complicated.
You must install Server on your PC(Apache httpd or apache tomcat or other based on your interest). A server listens to request from clients. When your mobile is connected to your pc(doesn't matter wire or wireless), you can make a request to an url(say, localhost:8080/welcome) from your app.
Create an applet and connect it with your web application(in the server) using java.net.URL and java.net.URLConnection.
On performing some operation on the client, call the url of the server application and forward the response to the applet.
What I mean is like servers on video games. You can run an application and it will set up a server on your computer with an IP and a port.
For example, how would you make an application where one host application sets up a thing where it has an IP and a port, and another computer that has access to the internet as well can type in the IP and port and it would be able to communicate with the host? I mean simple communication, like sending a boolean or String.
And would there be any security problems that would be needed to fix?
I guess I grasp the concept of your question...
You want two computers to connect via internet right? If that is the case, then you will have to use a thing called "sockets" that do connections between computers. About the server thing, well, for starters the client must always know what IP the server as (direct IP or by a DNS), and then you can connect your client to your server. There is a tutorial for sockets at the java pages: http://download.oracle.com/javase/tutorial/networking/sockets . About security issues, well, you must make sure that your server can handle anything that comes from the client (i really mean everything), i mean, accepting every type of data that is supposed to receive and deny everything that is not (trash per say). If you have that in mind then there is no problem (and of course, the server must have a firewall also to control the sockets, but that's not up to you).
Here is an example of how to use sockets to send a string from a server to a client.
http://www.java2s.com/Code/Java/Network-Protocol/StringbasedcommunicationbetweenSocket.htm
The site has about 20 examples of how to do what you are trying to do. In general I find this site to be the best JAVA resource that I know.
In general, the thing you probably want is a Socket. Sockets allow you to send bytes to an endpoint via TCP or UDP. This is very low-level, though, and are somewhat tricky because you have to design your own application protocol. You may want to use something that offers more abstraction.
Java sockets expose a stream interface so you could just encode integers as strings, for instance, and send them line by line, or you could do something fancier and more efficient like using a DataOutputStream to wrap it.
Handling the following issues can improve security.
If you have router ,set different ports for routing.
Example: If you are running server say on port 6001, map a virtual port say 9001 , which would be exposed to public.
DDos
IP Restriction - Not every user can access your machine !
Enabling router firewall does handle most of the issues.
I have a Java program running on two computers that are both on the same network. I would like to have these applications become aware of each other, so they could communicate directly as opposed to communicating with the server to relay messages.
I believe i may have a solution as to how this would work, but am unable to find any examples to compare my solution against. Do you guys know how this problem is usually solved?
There is a good library that implements the Zeroconf / Bonjour standard in plain java at http://jmdns.sourceforge.net/
This basically relieves you from the protocol burden and allows you to advertise and lookup service providers based in logical names (That's what iTunes or Mac printing does for example).
This book http://www.amazon.com/Zero-Configuration-Networking-Definitive-Guide/dp/0596101007 explains all basic concepts.
You could get them to do a UDP multicast within a LAN environment to identify the programs using protocol messages then have a stored cache of each other's identity and then use TCP to connect and do main exchanging of messages (which is more reliable than UDP). Or you can simply proceed with UDP messaging only if you want to.
You can search for multicasting in Java online.
Some multicast related links:
http://download.oracle.com/javase/1.4.2/docs/api/java/net/MulticastSocket.html
http://www.javafaq.nu/java-article817.html
A good multicast chat software you can reference:
http://sourceforge.net/projects/mc2/
One way would be to send a broadcast to see who's out there, then implement a GUI to show the user what other peers are there and give an option to connect to. (The broadcast will give you the IP address of everybody there.)
Once you know who to connect to, you simply open a TCP connection (or use UDP if it is time-critical) and you're done.
Btw, this is for IPv4 - IPv6 doesn't have broadcast (although something similar).