Telnet Port connectivity from one server to another through JSP - linux

Hi All,
I want to create a JSP page where I will ask user to give the source host and port and also destination host and port.
Following combination of source and destination OS is possible
Unix->Unix/Windows/zOS Windows-> Unix/Windows/zOS zOS ->
Unix/Windows/zOS
With these inputs I want to connect to the source server and fire this command telnet $ip $port to the destination. If the telnet connectivity is successful it should return success and else error.
I want to create the logic non-interactive that it should not require any password to login the source for checking telnet connectivity.
Is there any such library or any mechanism available so that I could make this feasible?

Why not use Apache Commons Net?
TelnetClient telnet = new TelnetClient();
try {
telnet.connect("rainmaker.wunderground.com", 3000);
} catch(IOException e) {
// failed
} finally {
telnet.disconnect();
}

Related

Pyads connection refused with Beckhoff running Twincat 3

I am trying to make a connection from a server running Ubuntu to a Beckhoff PLC with TwinCAT 3. With Windows everything works fine but with the same server on Linux I can't get a connection.
The Linux server has a static IP and in the route manager in the PLC I can find the route and see the server. I have tried adding the route by the route manager in the PLC and with "add_route_to_plc" but both ways my connection is refused. I have already turned off all firewalls. Any of you guys any idea what goes wrong here? In the attachment I have added some picture to see my settings and code that I try to run.
Python error: "connection closed by remote"
Python code:
import pyads
SENDER_AMS = '192.168.1.180.1.1'
PLC_IP = '192.168.1.100'
PLC_USERNAME = 'Administrator'
PLC_PASSWORD = '1'
ROUTE_NAME = 'GID_TEST_ROUTE'
HOSTNAME = 'Grid-stabilizer'
pyads.open_port()
pyads.set_local_address(SENDER_AMS)
pyads.add_route_to_plc(SENDER_AMS, HOSTNAME, PLC_IP, PLC_USERNAME, PLC_PASSWORD, route_name=ROUTE_NAME)
pyads.close_port()
plc=pyads.Connection('192.168.1.100.1.1', pyads.PORT_TC3PLC1)
plc.open()
plc.read_state()
If you are running python on linux and the plc on windows try
plc=pyads.Connection('192.168.1.100.1.1', pyads.PORT_TC3PLC1, PLC_IP)
This will create a route on the linux system. In your code the ip is missing to create a proper route.
Check the port of your plc. It should be 851.

Force selenium-webdriver to bind to localhost

When using selenium-webdriver, something attempts to bind to a port, listening for connections from the unspecified IPv6/IPv4 host (:: / 0.0.0.0). This triggers a firewall message.
I'd like to avoid this firewall message by forcing whatever this is to bind only to localhost, but I can't find any clues about what this server is or how to configure it.
Example code which replicates the issue:
const webdriver = require('selenium-webdriver');
const driver = new webdriver.Builder().forBrowser('chrome').build();
setTimeout(() => {
driver.quit();
}, 10000);
On macOS, this shows the prompt:
Do you want the application “node” to accept incoming network connections?
Obviously choosing "deny" still allows the tests to run (since everything is local anyway), and after selecting this option the OS remembers the choice until Node is updated, but I'd like to lock-down the test so that this isn't an issue.
What is causing this? How can I configure it?
You can use Selenium Standalone Server and bind it to a specific IP address. Additionally you can disable IPv6 addresses lookup.
Launch Selenium Standalone Server like:
java -Djava.net.preferIPv4Stack=true -jar selenium-server-standalone-x.xx.x.jar -host 10.20.30.40
Amend your webdriver initialization code to explicitly set the Selenium Server address like:
const driver = new webdriver.Builder().forBrowser('chrome').usingServer('http://10.20.30.40:4444/wd/hub').build();
replace this 10.20.30.40 with the IP address of your choice (the IP address or alias must exist on the system where you run the test)
References:
Selenium with JavaScript - The Standalone Selenium Server
Connecting Selenium Hubs to Cloud Server

Telnet using JMeter 3.3

I am using Jmeter 3.2 and I need to do a telnet connection and parse the response.
Is it possible using Jmeter 3.2 or adding any plugin?
What I need to achieve is what I would do using this command line
telnet
open [IP] [PORT]
and understand if the connection is established or not.
Also I wonder what is the effective difference if I simply use a TCP Sampler.
Thanks
Given you have groovy tag here's how you can test the connectivity using Socket class, the example code would be something like:
def sock = new Socket()
sock.setSoTimeout(1000)
sock.connect(new InetSocketAddress("example.com",80))
if (sock.isConnected()) {
log.info('Connection established')
}
else {
log.info('Server is not listening')
}
Also be aware that you can invoke telnet command directly using String.execute() method like:
"telnet example.com 80".execute().text
And last but not the least, you can run an arbitrary command or program using JMeter's OS Process Sampler.

Select IP Addresses which use a specific port

My idea here is create a website where the user is able to click a button which will look into the IP Addresses to see which one is using a certain port, for example:
I want to search for the IP Addresses which are communicating with the localhost that are using the port #3620 (which is obviously being used) and a code will show all the IP Addresses.
My question here is to see if this is possible and if it is, can someone give a brief idea of how this could be done?
For seeing if a port is open check out this:
In C#, how to check if a TCP port is available?
You could even loop over all port numbers for an IP address and check to see what ones are open.
TcpClient tcpClient = new TcpClient();
try
{
tcpClient.Connect("127.0.0.1", 9081);
Console.WriteLine("Port " + 9081+ " Open");
}
catch (Exception)
{
Console.WriteLine("Port " + 9081+ " Closed");
}

Cannot get simple SignalR Azure worker role to work

I am trying to get a simple WebSocket server going using SignalR, OWIN and Azure Worker Roles.
WorkerRole.cs:
public class WorkerRole : RoleEntryPoint
{
public override void Run()
{
string url = "http://" + RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["MyEndpoint"].IPEndpoint;
using (WebApp.Start<Startup>(url))
{
Trace.WriteLine(String.Format("Server running on {0}", url));
}
while (true)
{
}
}
/* ... */
}
Startup.cs:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
MyHub.cs:
public void Send(string name, string message)
{
Clients.All.addMessage(name, message);
}
The Endpoint "MyEndpoint" is defined in the Service as http, public and private port 5001.
After starting the service, it shows up under Azure Compute Emulator as running on 5001. However, if I try to connect to ws://127.0.0.1:5001/signalr (or just ws://127.0.0.1:5001) there is no response. I am using two different web socket clients for this purpose (both are Chrome plugins and they both worked fine using other WebSocket servers).
Questions:
1) Is there anything obviously wrong with my setup?
2) Do I need to use the SignalR JS client libraries to connect to the SignalR server, or should any vanilla client implementing the WebSocket protocol be able to connect?
I know this is a bit of an old post but just in case someone needs it...
1) There are two problems you need to address.
First of all, Start method in:
using (WebApp.Start<Startup>(url))
{
Trace.WriteLine(String.Format("Server running on {0}", url));
}
returns an IDisposable (hence the using(...){} block) means it is immediately disposed after creation since execution continues right passed Trace.Writeline(...) without pause.
It's also a bit tricky running these things under the Azure Compute Emulator for a few reasons, mainly because it remaps ports to avoid collisions. If you open up a command prompt and run
netstat -a
you'll find that you have open ports (listening) looking something like this (in my case I'm using port 81):
TCP 127.0.0.1:82 MyComputer:0 LISTENING
TCP 127.0.0.3:81 MyComputer:0 LISTENING
In the general console ouput of Visual Studio, you'll also most likely see something like
"Windows Azure Tools: Warning: Remapping private port 81 to 82 in role 'MyRoleThingy' to avoid conflict during emulation."
This all means that in order to connect to the server you're hosting using your worker role, you'll have to connect to port 82 instead of 81 (probably 5002 in your case).
2) If you implement the protocol, anything should work I think. Managing an initial connection on the port should always work.

Resources