Error While exiting Configuration mode using Python Script - network-programming

It's been long since I opened stack websites.
please ignore any mistakes.
I am using telnetlib library to login into my Multilayer switch on GNS3.
I am Successfully able to configure loopback interfaces using script and execute show commands in it, including the show commands on configuration mode. Example : "do sh ip int br" OR "do sh run".
The issue is when my script does it's configuration and tries to exit then it is not exiting and the code is stuck.
I have to manually login into device and clear the vty line session to get the output.
Catch is : for both commands "exit" and "end" the code is removing the initial "e" which is happening only to the last "exit" and/or "end.
Below is the code :
import getpass
import sys
import telnetlib
HOST = input("Enter Device IP: ")
user = input("Enter your telnet username: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
tn.write(b"enable\n")
#tn.write(b"xxpasswordxx\n")
tn.write(b"conf t\n")
tn.write(b"int loop 2 \n")
tn.write(b"ip address 1.1.1.2 255.255.255.255 \r\n")
tn.write(b"exit \r\n") **>>>>> This exit is working fine.**
tn.write(b"do wr\n")
tn.write(b"exit \r\n") **>>>>> This exit is working fine.**
tn.write(b"sh ip int br \n")
tn.write(b"end\n") **>>>>> This exit/end is not working no matter if I use "exit" or "end", it removes initial "e"**
print (tn.read_all().decode('ascii'))
Output of switch CLI :
ESW1#
ESW1#
*Mar 1 03:00:07.635: %SYS-5-CONFIG_I: Configured from console by user1 on vty0 (20.20.20.6)
ESW1#sh users
Line User Host(s) Idle Location
* 0 con 0 idle 00:00:00
162 vty 0 user1 idle 00:00:22 20.20.20.6
Interface User Mode Idle Peer Address
ESW1#clear line vty 0
[confirm]
[OK]
ESW1#
Output of Windows-command line/ When I execute the script :
Path:\P_Project\MyScript>python Telnet_1.py
Enter Device IP: 20.20.20.1
Enter your telnet username: user1
Password:
***************************************************************
This is a normal Router with a Switch module inside (NM-16ESW)
It has been pre-configured with hard-coded speed and duplex
To create vlans use the command "vlan database" in exec mode
After creating all desired vlans use "exit" to apply the config
To view existing vlans use the command "show vlan-switch brief"
Alias(exec) : vl - "show vlan-switch brief" command
Alias(configure): va X - macro to add vlan X
Alias(configure): vd X - macro to delete vlan X
***************************************************************
ESW1#enable
ESW1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
ESW1(config)#int loop 2
ESW1(config-if)#ip address 1.1.1.2 255.255.255.255
ESW1(config-if)#exit
ESW1(config)#do wr
Building configuration...
[OK]
ESW1(config)#exit
ESW1#sh ip int br
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 20.20.20.1 YES manual up up
FastEthernet0/1 unassigned YES NVRAM administratively down down
FastEthernet1/0 unassigned YES unset up down
FastEthernet1/1 unassigned YES unset up down
FastEthernet1/2 unassigned YES unset up down
FastEthernet1/3 unassigned YES unset up down
FastEthernet1/4 unassigned YES unset up down
FastEthernet1/5 unassigned YES unset up down
FastEthernet1/6 unassigned YES unset up down
FastEthernet1/7 unassigned YES unset up down
FastEthernet1/8 unassigned YES unset up down
ESW1#nd
Translating "nd" >>>> To print this error I have to execute the command "clear line vty 0" on switch (refer the output of switch CLI)
Translating "nd"
% Unknown command or computer name, or unable to find computer address
ESW1#
I have also tried to add space, extra "e" in the last exit command. however still getting the same error
Please let me know if I am missing something/anything.
Environment details:
Python 3.10.6
GNS3 2.2.21
Switch is L3 Multilayer Switch and is IOS router running on local PC as server
PC is connected to GNS3 via loopback interface on PC and cloud on GNS3
Topology on GNS3 : Multi-layer Switch=======L2Switch=====Cloud
The same script is working fine with Cisco Router-7200
Please let me know if any other information is required.
----- TIA

Resolved by encoding it to string
tn.write(str.encode("exit\n"))

Related

U-Boot writes incorrect CRC in env

I'm using u-boot on raspberry pi 4, A/B booting from USB attached SSD, integrated with mender without yocto. Everything works fine except the env saving: initially configured to use MMC and offsets, fw_printenv complained about a bad CRC and output the default config instead. I changed the env saving to FAT files on the boot partition, and I'm now troubleshooting 2 issues:
uboot.env does not get written by issuing saveenv in the u-boot prompt
uboot-redund.env gets written but its CRC is incorrect.
I'm checking the CRC by issuing the fw_printenv command from linux. Its config file states:
/boot/u-boot/uboot-redund.env 0x0000 0x4000
U-Boot is compiled with 0x4000 as env size, and using hexdump to check the file shows a correct file with a length of 0x4000.
When booting up, u-boot outputs the following log over TTL serial:
U-Boot 2021.07-rc2-00246-gd64b3c608d-dirty (Jun 16 2021 - 12:16:24 +0200)
DRAM: 7.9 GiB
RPI 4 Model B (0xd03114)
MMC: mmcnr#7e300000: 1, emmc2#7e340000: 0
Loading Environment from FAT... In: serial
Out: vidconsole
Err: vidconsole
Net: eth0: ethernet#7d580000
PCIe BRCM: link up, 5.0 Gbps x1 (SSC)
starting USB...
Bus xhci_pci: Register 5000420 NbrPorts 5
Starting the controller
USB XHCI 1.00
scanning bus xhci_pci for devices... 3 USB Device(s) found
scanning usb for storage devices... 1 Storage Device(s) found
Hit any key to stop autoboot: 0
which shows that u-boot does load the env from FAT correctly.
How can I investigate further why u-boot does not write uboot.env, and why when it does write uboot-redund.env, writes it with a wrong CRC from fw_printenv's point of view?
env save
In function env_fat_save only one file is written. If CONFIG_SYS_REDUNDAND_ENVIRONMENT is defined, alternatively either file CONFIG_ENV_FAT_FILE_REDUND or file CONFIG_ENV_FAT_FILE is written.
You have to execute the command env save twice if you want to write both files.
Command env infoindicates which instance was written last via field env_valid:
=> env select FAT
Select Environment on FAT: OK
=> env info
env_valid = invalid
env_ready = true
env_use_default = false
=> env save
Saving Environment to FAT... OK
=> env info
env_valid = redundant
env_ready = true
env_use_default = false
=> env save
Saving Environment to FAT... OK
=> env info
env_valid = valid
env_ready = true
env_use_default = false
=>
fw_printenv
When using fw_printenv you must specify the configuration which matches your U-Boot build. By default file /etc/fw_env.config is used. You can pass the configuration file on the command line:
tools/env/fw_printenv -c fw_env.config
This is what your configuration file could look like:
uboot.env 0x0000 0x2000
uboot-redund.env 0x0000 0x2000
There is an example file in tools/env/fw_env.config explaining the available fields.

How to debug Oracle 11g packages/procedures in docker with SQL Developer?

I'm running an Oracle 11g image (https://hub.docker.com/r/oracleinanutshell/oracle-xe-11g) on a docker container.
I'm creating the container with the debug option as explained:
docker run --name oracle-xe-11g -idt -p 1521:1521 -p 49161:8080 -e ORACLE_ALLOW_REMOTE=true oracleinanutshell/oracle-xe-11g /bin/bash
After that I logged in the container as sudo, configured the listener.ora with the correct hostname, everything following this guide (it's in pt-Br, but the commands are easy to understand)
http://loredata.com.br/2017/08/31/rodando-o-oracle-no-docker/
I can connect with SQL Developer and with my main application running in a Wildfly server, but for support purposes I need to debug some package and stored procedures.
I compiled all my packages and procedures to allow debugging, gave the debug permissions to the user, but when I try to debug a procedure in a package using the SQL Developer default debug options I get the following error:
Conectando ao banco de dados SFW_DOCKER.
Executando PL/SQL: ALTER SESSION SET PLSQL_DEBUG=TRUE
Executando PL/SQL: CALL DBMS_DEBUG_JDWP.CONNECT_TCP( '127.0.0.1', '20587' )
ORA-30683: falha ao estabelecer conexão com o depurador
ORA-12541: TNS:não há listener
ORA-06512: em "SYS.DBMS_DEBUG_JDWP", line 68
ORA-06512: em line 1
Processo encerrado.
Desconectando do banco de dados SFW_DOCKER.
It says there's no listener, but I'm sure everything is running fine.
I also tried to run in ports 4000-4999 exposing them in the create container command and forcing SQL Developer to use them, but I get the same error.
Anyone can help me with this question?
To solve try:
Use IPv4 from your local machine
Set 'Debugging Port Range' from 4000 to 4000
Check the option 'Prompt for Debugger Host for Database Debugging'
SQL Developer -> Tools -> Preferences -> Debugger
Debugger configuration
I solved it by setting DatabaseDebuggerDisableJDWP=true in ide.properties. On linux this can be done with this:
find ~/.sqldeveloper/ -name ide.properties -type f -exec sh -c "echo 'DatabaseDebuggerDisableJDWP=true' >> {}" \;

LPQ on Windows 8 doesn't find my printer

I have enabled the LPD and LPR on a Windows 8.
I want to print some files using the LPR command, but i can't even find the printer with the LPQ.
I can print normally with the printer through (ctrl + p), but i can't find it with the LPQ command.
C:\>lpq -S localhost -P HiTi_P510L
Servidor LPD do WindowsErro: the specified printer doesn't exists.
If i try to run the LPR directly i have the same error saying that the printer doesn't exists.
C:\>lpr -S 127.0.0.1 -P HiTi_P510L camila.jpg
Erro: o servidor de impressão não aceitou a requisição. Trabalho interrompido.
The event log:
LPD refused the job \\127.0.0.1\HiTi_P510L because the specified printer doens't exist on this computer.
net view:
C:\Windows\system32>net view \\myserver
Recursos compartilhados em \\myserver
Nome do compartilhamento Tipo Usado como Comentário
--------------------------------------------------------------
HiTi_P510L Impressão P510L
Comando concluído com êxito.
C:\Windows\system32>
update: port 515 is listening.
C:\>netstat -an
Conexões ativas
Proto Endereço local Endereço externo Estado
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 0.0.0.0:515 0.0.0.0:0 LISTENING
TCP 0.0.0.0:2869 0.0.0.0:0 LISTENING
TCP 0.0.0.0:49152 0.0.0.0:0 LISTENING
...
I can also telnet localhost 515 which gives me a black screen, and after i press ENTER i have this:
☺
Conexão ao host perdida.
C:\Windows\system32>
Any suggestion?
UPDATE: There are two issues here. The answer to the question regarding LPR/LPD is resolved here while the other issue was relating to the actual print stream is answered at the bottom of this response.
Ensure your firewall is off (or at least allowing 515 to pass through). Also, ensure you are using the IP of your network adapter and not local host as LPD tends to bind to an actual IP address.
If you want to ensure that your data is passed through without modification / encoding then use -o l in the command line. For example:
lpr -S <workstation_ip> -P <printer_share> -o l test.ps
lpr -S 192.168.1.6 -P P510L -o l test.ps
Also ensure the file you are sending is actually supported by the print device. While some printers support graphic formats most are expecting PCL, PS, XPS, PDF etc. Some support TIF and other JPG etc. Ensure the file you are sending is supported by the device.
In the end the issue appears to be the proprietary nature of the device and as such, the requirement is there to push the file through the print driver. One simple way is to use a graphics application that supports command line printing. One option is MS Paint.
mspaint /pt IMG_1234.jpg "Hiti P510L"
The printer name (Hiti P510L) is the name that appears in the devices and printers screen in Windows.

Query regarding Zookeeper Windows API start/stop, using Zk as a windows service(using prunsrv)

I am using zookeeper in my product(3.3.3).
While working with zookeeper on Windows, I am creating a service(using prunsrv) ,
I have few queries and issues. Listed them all,
Issues:
1) zkServer.cmd didn’t start on Win server 2008 machine & Win 7 Enterprise(64 bit both), had to replace the following line,
java "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %*
to
java "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%"
And it worked, could it be fixed in some other way?
2) In the zoo.cnf I specified the dataDir, still it creates some other directory (bin/zookeeper-3.4.5zookeeper-3.4.5data/ version-2/snapshot) and stores the snapshots there.
Queries:
1) There is no start/stop with zkServer.cmd as it is in zkServer.sh, so basically it is started with zkServer.cmd but to stop I do a Ctrl+C/Z
So if I start the process, it is a foreground process and gets killed when I do a ctrl+C
2) I have to create a zookeeper service, and I am using prunsrv to do that. I figured out the following 2 ways to do so.
a)
prunsrv //IS//Zookeeper --DisplayName=" ZOOKEEPER Service" --Description=" ZOOKEEPER Service" --Startup=auto --StartMode=exe --StartPath=%ZOOKEEPER_HOME% --StartImage=%ZOOKEEPER_HOME%\bin\zkServer.cmd --StopTimeout=5 --LogPath=%LOGS_DIR% --LogPrefix=zookeeper --LogLevel=Info --PidFile=zookeeper.pid --StdOutput=auto --StdError=auto
b)
cd %ZOOKEEPER_HOME%\bin\
call "%~dp0zkEnv.cmd"
set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain
prunsrv //IS//Zookeeper --DisplayName=" ZOOKEEPER Service" --Description=" ZOOKEEPER Service" --Jvm="%JVM_DLL%" --JvmOptions=!JAVA_OPTS! --Environment=zookeeper.log.dir=%ZOO_LOG_DIR%;zookeeper.root.logger=%ZOO_LOG4J_PROP%; --Startup=auto --LibraryPath=%LIB_DIR% --StartMode=jvm --Classpath=%CLASSPATH% %ZOOMAIN% %ZOOCFG% --StartClass=org.apache.zookeeper.server.quorum.QuorumPeerMain --StartMethod=start --StopMode=jvm --StopClass=org.apache.zookeeper.server.quorum.QuorumPeerMain --StopMethod=stop --StopTimeout=10 --LogPath=%LOGS_DIR% --LogPrefix=zookeeper --LogLevel=Info --PidFile=zookeeper.pid --StdOutput=auto --StdError=auto
basically in the second approach I am myself doing all tasks done by the zkServer.cmd
=>> My Query is in the second step(2b), that to stop the service there should be a stop method exposed, so that when I stop the service it is called.
So right now if I create a service and start it, ZK runs fine, but stopping it takes indefinitely, so I have to go and kill the process.
Is there some stop() for the same, I see a shutdown() but there is no description for it
I went through the class org.apache.zookeeper.server.quorum.QuorumPeerMain, here the main() is the start method( if my understanding is correct), and there should be some method to shutdown the process.
Just got the following link
https://issues.apache.org/jira/browse/ZOOKEEPER-1122, exposes a start/stop, but the stop has some issues
it throws the following error:
E:\zookeeper-3.4.5\zookeeper-3.4.5\bin>zkServer.cmd stop
"JMX enabled by default"
"Using config: E:\zookeeper-3.4.5\zookeeper-3.4.5\bin\..\conf\zoo.cfg"
"Stopping zookeeper ... "
ERROR: The process with PID 452 (child process of PID 4) could not be terminated.
Reason: This is critical system process. Taskkill cannot end this process.
ERROR: The process with PID 4 (child process of PID 0) could not be terminated.
Reason: Access is denied.
ERROR: The process with PID 0 (child process of PID 0) could not be terminated.
Reason: This is critical system process. Taskkill cannot end this process.
STOPED
I am running this stop command on a Administrator console.
E:\zookeeper-3.4.5\zookeeper-3.4.5\bin>tasklist | findstr "java"
java.exe 10324 Console 1 36,036 K.
Any help would be highly appreciated
So what you want to do is run Zookeeper as a Windows service. I had the same requirement, here is the solution I have chosen:
Prereqs: Zookeeper & prunsrv
Set ZOOKEEPER_SERVICE environment variable to the name of the windows service to create, and ZOOKEEPER_HOME to the path to the zookeeper home folder. Then,
prunsrv.exe "//IS//%ZOOKEEPER_SERVICE%" ^
--DisplayName="Zookeeper (%ZOOKEEPER_SERVICE%)" ^
--Description="Zookeeper (%ZOOKEEPER_SERVICE%)" ^
--Startup=auto --StartMode=exe ^
--StartPath=%ZOOKEEPER_HOME% ^
--StartImage=%ZOOKEEPER_HOME%\bin\zkServer.cmd ^
--StopPath=%ZOOKEEPER_HOME%\ ^
--StopImage=%ZOOKEEPER_HOME%\bin\zkServerStop.cmd ^
--StopMode=exe --StopTimeout=5 ^
--LogPath=%ZOOKEEPER_HOME% --LogPrefix=zookeeper-wrapper ^
--PidFile=zookeeper.pid --LogLevel=Info --StdOutput=auto --StdError=auto
Add a zkServerStop.cmd file in zookeeper bin folder with the following content:
#echo off
setlocal
TASKLIST /svc | findstr /c:"%ZOOKEEPER_SERVICE%" > %ZOOKEEPER_HOME%\zookeeper_svc.pid
FOR /F "tokens=2 delims= " %%G IN (%ZOOKEEPER_HOME%\zookeeper_svc.pid) DO (
#set zkPID=%%G
)
taskkill /PID %zkPID% /T /F
del %ZOOKEEPER_HOME%/zookeeper_svc.pid
endlocal
(Of course it needs the two environment variables ZOOKEEPER_HOME & ZOOKEEPER_SERVICE to be set)
Hope it helps,
Guillaume.

BigCouch cluster connection issue

I have successfully setuped BigCouch on two different machines. Both of them run locally very well. When I joins them in a cluster using one of or both this command: curl -X PUT machine1:5986/nodes/bigcouch#machine2 -d {} curl -X PUT machine2:5986/nodes/bigcouch#machine1 -d {}
I always receive positive results. The database nodes contains two documents bigcouch#machine2, bigcouch#machine1. But in fact, it is always erreous. I saw this error message in the command line of BigCouch
=*ERROR REPORT==== 9-Dec-2011::20:01:40 === Error in process <0.3117.0> on node 'bigcouch#machine1.fr' with exit value: {{rexi_DOWN,noconnect},[{mem3_rep,rexi_call,2},{mem3_rep,replicate_batch,1},{mem3_rep,go,3},{mem3_rep,go,2}]} <148>1 2011-12-09T19:01:40.559992Z machine1 twig <0.159.0> -------- - mem3_sync nodes -> 'bigcouch#machine2' {{rexi_DOWN,noconnect}, [{mem3_rep,rexi_call,2}, {mem3_rep,replicate_batch,1}, {mem3_rep,go,3}, {mem3_rep,go,2}]} <148>1 2011-12-09T19:01:40.560106Z machine1 twig <0.159.0> -------- - mem3_sync dbs -> 'bigcouch#machine2' {{rexi_DOWN,noconnect}, [{mem3_rep,rexi_call,2}, {mem3_rep,replicate_batch,1}, {mem3_rep,go,3}, {mem3_rep,go,2}]} <148>1 2011-12-09T19:01:40.560205Z machine1 twig <0.159.0> -------- - mem3_sync _users -> 'bigcouch#machine2' {{rexi_DOWN,noconnect}, [{mem3_rep,rexi_call,2}, {mem3_rep,replicate_batch,1}, {mem3_rep,go,3}, {mem3_rep,go,2}]} [error] [emulator] [--------] Error in process <0.3198.0> on node 'bigcouch#machine2' with exit value: {{rexi_DOWN,noconnect},[{mem3_rep,rexi_call,2},{mem3_rep,replicate_batch,1},{mem3_rep,go,3},{mem3_rep,go,2}]} <147>1 2011-12-09T19:01:45.560979Z machine1 twig emulator msg - Error in process <0.3198.0> on node 'bigcouch#machine1' with exit value: {{rexi_DOWN,noconnect},[{mem3_rep,rexi_call,2},{mem3_rep,replicate_batch,1},{mem3_rep,go,3},{mem3_rep,go,2}]}*
Maybe it's the firewalled? If Yes, plese tell me the range port to let nodes connect each other. If not, Please explain it to me and how to solve it to connect them.
In the document, they ask that nodes can ping each other and the nodes set the same magic cookie. My machines can ping each other, but what is magic cookie?
Occasionally you can see this error when a node is first connected as there are various processes that receive update messages and monitor the other nodes as well as an internal replicator. These messages are harmless but if you see "noconnect" persistently then something is wrong.
On each instance there is a file, /etc/vm.args in which you will see two values of interest, -name and -setcookie The first -name corresponds to the doc id you must use when connecting the nodes and the second is the magic cookie that must be the same on all the erlang nodes for them to talk to one another. If this cookie isn't set it defaults to the value in ~/.erlang-cookie
When you execute "make dev" it will build a 3 node cluster that you can inspect to see how these bits should be set.
Also you only need to run the connect on one side, .eg. node2 to node1 as the internal replicator will sync the nodes dbs across the cluster

Resources