How to get the details using telnet API - java

Is it possible to get the following information via Telnet?
Software version
config files
config register
information on traffic and errors
If you have sample code that you could share that would be really useful so that I can procceed further with your help .
I will be thankful for your valuable replies.

Telnet is nothing more than a communication protocol to generally a shell interface on another Unix machine. The remote telnet daemon will most likely invoke authentication and shell processes so everything that you are requesting is yes, possible though you will thus require authentication.
As you know telnet for shell is primarily used internally inside secured networks and rarely on the 'net any longer.

Telnet is wrong protocol to do this kind of stuff. It is an (out-dated) protocol for interactive terminal sessions. You should be looking at "ssh" to execute commands on the remote machines, and then figuring out which commands you need to execute to extract the information of interest to you.
Some of the information you are after may also (in theory) be available using SNMP, but things like configuration files and application versions won't. The "ssh" approach will allow you to harvest any information that is available via commands run from the command line.
Injecting Java into the mix is almost certainly a bad idea. Java is best at tasks that are platform independent, but what you are trying to do is inherently platform specific.

Related

Java remote interactions

I'm in internship, and my mission is to build a deployment program in Java. My approach was based on a "tasks to do for a deployment" model with dynamic instanciation (but this is not the point). Every task does something locally or on the remote server (sometimes both). For example, I have a Copy task which copies a local file to the remote server. Got some tasks like this for basic interactions (Move, Delete, ...).
The point is, each deployment module is a server which has different parameters (OS, connection params, ...) and basic programs. One of them is a Linux server, so I figured I could use SSH (with JSCh) to do the job. But the other is a Windows machine, with no SSH whatsoever. I searched everywhere for several days to find what could be used, with no results.
So here is my question:
what Java API should I use to get the job done?
Is it possible with Telnet or FTP?
Is it possible at all without ssh ?
Little detail: I don't have any control on remote servers, I can't install new protocols or programs, nor have a RMI server launched on them.
Thanks for your answers.
There are a few options to interact with a remote Windows server. If your local Java application is running on Windows (that is, both your source and target server are running Windows), you can spawn a new process and execute PowerShell commands - see this link for an example.
There are ways to copy and delete files on a remote server using PowerShell. Since you didn't fully specify your requirements, I don't know if that covers all your use cases or not.
If your application does not run on Windows, you'll have to resort to a pure Java solution like j-Interop to connect to the remote system using DCOM / WMI. See this page for a good introduction to WMI and j-Interop. Word of warning though - getting DCOM to work requires some configuration changes, specifically changing permissions on registry keys, on modern versions of Windows (Windows 7 and up).

Java application to execute shell files from different servers

I would like to know if the following is possible:
I have to create a Java application that runs .sh files from different servers, I have my class to execute shells, with Runtime and Process, it runs .sh files from my computer, the thing now is that I would like to know if instead of my location be
process = runtime.exec("/home/user/Documents/example.sh");
could be:
process = runtime.exec("180.150.2.***/server/user/Documents/serverExample.sh");
and the thing is, that to get the .sh files from server, I have to login, this application could be a desktop application or a web application, but has to be in Java, so, how could I do this?
I appreciate your help.
Chema.
Basically, I don't think you can do that, the way you are trying. The Runtime.exec(...) will delegate to the OS to perform the actual execution.
There are any number of ways to achieve what you want, either purely in Java or via additional utilities based on the OS.
You could SSH or telnet to the remote machine and execute the commands via those interfaces.
You could write a client server app, where the server would allow you to send commands to it to be executed on your behalf (but you must understand that this is a massive security risk).
Check out Jsch or Ganymed SSH. I have used the latter to perform ssh/scp tasks programmatically.

How can I provide a telnet interface to my Java application?

I want to provide a telnet interface to my Java application, primarily so that developers can interact with the app, view debugging information, etc - before we've implemented our full end-user facing GUI.
Can anyone recommend an easy and effective way to do this? I've looked at embedding the scala interpreter, but it doesn't seem to be accessible via telnet. Ditto for Beanshell (which I'm not too keen on anyway as I believe its unmaintained).
Couple of options:
Grizzly for embedding a generic server (http://grizzly.java.net/)
Mina is another similar option (http://mina.apache.org/)
Instead of Telnet, it might be easier to just embed a web server. Not that a CLI isn't cool and all, but it might be a bit easier/more friendly.
Jetty http://docs.codehaus.org/display/JETTY/Embedding+Jetty
Tomcat http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/catalina/startup/Embedded.html
JMX is great for monitoring but the UI isn't very good for 'writing' data. NetBeans has some nice tutorial projects in it.
I think of all of the options above the embedded Jetty is probably the easiest.
Have you considered using JMX? It's built right into the jdk and can provide remote access via jconsole to any methods you configure it too.
Now it's not going to work exactly like ssh or telnet, so it might not meet your needs fully. But if your goals is access to invoking methods and debugging information remotely, that's kind of it's main purpose.
The bonus is after you build a UI you can still use the JMX stuff to monitor performance after it's goes live.
Try Jsh its good for telnet related stuff.
I faced this same issue and came up with a slightly ugly combination of nvt4j (telnet server code) plus JLine (Java command line history editor, tab completion, etc.). My application listens on localhost for telnet connections and runs a CLI console loop when it gets a connection.
One key trick is to get the rows and columns information (which is sent via the telnet protocol) transferred from nvt4j to JLine so things don't go haywire when you reach the end of the line.
If you only need a line-mode interface via Telnet, you could use my Java class TelnetStdioRedirector.

Single sign-on in Java / VNC

Background
On the project I work on we have GUI applications running on several different servers. Due to their user interface similarities I am investigating combining their OMIs into a single unified interface. Currently these applications are all remotely viewable via VNC. I plan to take advantage of this by having the master display run several VNC viewers under the covers and wrap an interface around these VNC sessions to make them appear like native applications.
Problem
I am looking for pointers for architecting a single sign-on solution. I want to eliminate each application's individual login and instead have users login to the unified display only. When they do that they would then be automatically logged in to each of the individual apps.
Constraints
The applications are all Swing-based Java apps running on Linux.
Authentication is performed by a Windows 2003 Server machine with Active Directory.
I'd strongly prefer an off-the-shelf solution to a custom-built one.
Ideas
My investigation has pointed me towards Kerberos and GSSAPI. Kerberos's ticket-based mechanism seems well-suited to the task.
One tricky bit is that these applications are always running. I need the unified display to somehow "tell" them when the user has logged in. It's not like normal Kerberized programs where they will perform a Kerberos login at startup.
If I use Kerberos I'm not sure how to transfer tickets to the various application servers. Is there a standard way to transfer them? Do I just use "scp" or something? Or do I develop my own socket-based network protocol and have the Java programs connect to each other and transfer tickets that way?
I don't want to get too bogged down in the details, though. I'd appreciate even general ideas like "have you considered Technology X?" or "try XYZ instead of VNC, it does this for you."
Updates
I'll edit in answers and clarifications here...
Have you considered that some authentication must take place anyway and that VNC only exports the view to a running program, so a VNC session cannot transport tickets?
Yes, indeed. Java + VNC is what we have right now. I could change out VNC for something else if there's a better way to remotely view the apps. Without rewriting them, that is. The ideal solution would be to separate them into distinct client and server pieces and put all the GUI code into the client, but that's 5-star difficulty and I need 1- or 2-star.
Have you considered the case when two users log in the same time? Will they see the same app? Or will this be forbidden?
Yeah, I've considered that. They will either see the same app or it will be forbidden. Either solution is okay as far as this particular system goes, so this isn't a big deal.
Have you considered just using an X Server on your local host and export the clients applications windows?
Yeah, this would be great. Can this be done with already-running apps? I have to connect to these apps after they've already started. I can't start them on demand when somebody fires up the central viewer.
RealVNC Enterprise Edition supports AD authentication (~$50 per exported desktop). Perhaps you can simply let people auth into the apps that way. FreeNX supports PAM authentication so you could perhaps hack something together with winbind, especially if your linux dist makes AD setup easy.
One last thing is running your apps in VirtualBox which can run in a headless mode via RDP. You can authenticate against PAM and thus winbind. This also has the advantage of being windows friendly on the client side via Remote Desktop which is pre-installed or readily available for windows.
Okey, I will try and start this list. Have you considered...
JAAS? Should include the GSS API, but was very cumbersome the last time I tried it.
that some authentication must take place anyway and that VNC only exports the view to a running program, so a VNC session cannot transport tickets?
a browser based solution with an embedded Java VNC client? At least the IE is able to carry out kerberos authentication, I don't know about the other browsers, or HOW the IE does that.
the case when two users log in the same time? Will they see the same app? Or will this be forbidden?
just using an X Server on your local host and export the clients applications windows?
EDIT: More considerations:
When using the X Server variant, use Xmove to move the programs to the X Server.
You can use SSH authentication with private/secret keys and let the user enter one passphrase to connect all your servers. SSH agent is the keyword.
With the existing SSH connections, start XMove on all the machines, collect all GUIs and send them to the client. You could even write a little MainWindow, with Buttons for each app, and when clicked, export only one of the apps, so it seems like they have been started from the main GUI.

Call COM port from webpage

I'm looking for a way to call a COM port from a webpage.
I was thinking abut running a Java WebStart (or Flash?) program that opens a local web server that allows to interact with the COM port using JSONP.
Are there any show stopping security restrictions on the way that I don't know of? This should be possible:
use native libraries (Java COM bridge) from Java WS application
open a local port
access local port from javascript, likely using <script> tags
do all this without scaring users with "This website is trying to do something really nasty, get off as fast as you can" kind of messages :)
I've used a Java COM bridge before, so this shouldn't be the problem - at least as soon as I'm able to run native code.
So how would my JNLP file have to look like to get this working? Any alternatives to Java WS? Better install it as a daemon?
Impossible. This violates all sorts of very basic security principles, especially the part about do all this without scaring users with "This website is trying to do something really nasty, get off as fast as you can" kind of messages
This is EXACTLY what those messages are intended to prevent.
This article answers the first part of my question, the WS to COM approach that is: Juggling with DLLs, WebStart and Maven
Accessing an HTTP server on a local port should also be feasible as that's what Playdar does for instance.
What are you trying to achieve?
You need a standalone software that does the job. The user will have to install it. Like the security pathches.

Categories

Resources