Pyads connection refused with Beckhoff running Twincat 3 - linux

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.

Related

Could not find Host of Azure In App SQL Database

I've created a MySQL In App database for my Azure App, and got the connection string for it. This string is injected into the application.json, and then used to create the actual connection:
WebApplicationBuilder builder = // get it somewhere
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection")
builder.Services.AddDbContext<DatabaseContext>(options => options.UseMySQL(connectionString));
Only... no connection string works. The one with the port (Database=localdb;Data Source=127.0.0.1:53844;User Id=azure;Password=password) throws:
System.Net.Sockets.SocketException (11001): No such host is known.
And the one without the port (Database=localdb;Data Source=127.0.0.1;User Id=azure;Password=password) throws:
System.Net.Sockets.SocketException (10013): An attempt was made to access a socket in a way forbidden by its access permissions.
This question sugested another connection string (Server=127.0.0.1; Port=53844; Database=localdb; Uid=azure; Pwd=password), which weirdly enough also throws this exception, even though the port is defined:
System.Net.Sockets.SocketException (10013): An attempt was made to access a socket in a way forbidden by its access permissions.
And the manual suggests yet another string (server=localhost;database=localdb;user=azure;password=password) which again throws one of the two exceptions depending on if the port is present.
Connecting via the browser works fine, so I can confirm port, username and password work normally.
Just to be sure, I tried "localhost" as the host, too. Same results.
What am I doing wrong?
It's a mix out of all these connection strings:
server=localhost;port=53844;database=localdb;user=azure;password=password
(Port and server separated, but both present.)
Works for me right now.

How to get the server name in Python Django?

How to get the server name in Python Django? we hosted Django application in AWS - Apache machine which have more than 1 server and increased based on load.
Now i need to find from which server the particular request is made and from which server we got the response.
I am using Python 3.6, Django,Django restframework, Apache server on AWS machine.
I assume by server name you mean hostname,
to get your hostname you can use
import socket
socket.gethostname()
https://docs.python.org/3/library/socket.html#socket.gethostname
or you can query your instance metadata, here you'll get a richer result such as
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
events/
hostname
iam/
instance-action
instance-id
instance-type
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-hostname
public-ipv4
public-keys/
reservation-id
security-groups
services/
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
My opinion is try to use instance-id

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

change from adodb to php7.2-pgsql

Change phppgadmin connection from adodb to php7.2-pgsql
Tried running an SQL query on database from phppgadmin and got error "Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /usr/share/php/adodb/adodb-error.inc.php on line 114"
In my config.inc.php I don't see anything about defining a connection type
// Display name for the server on the login screen
$conf['servers'][0]['desc'] = 'PostgreSQL';
// Hostname or IP address for server. Use '' for UNIX domain socket.
// use 'localhost' for TCP/IP connection on this computer
$conf['servers'][0]['host'] = 'phppgadmin.com';
// Database port on server (5432 is the PostgreSQL default)
$conf['servers'][0]['port'] = 5432;
I would like to change the default connection from adodb to php7.2-pgsql
You need to run a newer version of phppgadmin with proper support for php7. I'd suggest just grabbing the code from git master at https://github.com/phppgadmin/phppgadmin

I get Network is unreachable in Java

Good day everyone!
I am making a DHCP Server for a project. I tried it in Windows and it worked. Now, I need to make it work on Linux. I used the same code and it can listen packets coming from port 67. However, every time I am about to send packets to the machine in KVM (Kernel Virtual Machine), I get an error at line containing "datagramsocket.send(response)" saying that Network is Unreachable. Btw, I am using a centOS as host and another centOS as guest machine. Bridge connection and firewall is disabled. How could I fix this problem? I am clueless.
Thanks in advance! :)
I used a dhcp4java API and here's a portion of my code:
if (replypacket != null){
InetAddress add = replypacket.getAddress();
int port = replypacket.getPort();
byte[] buf = replypacket.serialize();
DatagramPacket response = new DatagramPacket(buf, buf.length, add, port);
datagramsocket.send(response);
}

Resources