SSH C# & Cisco devices configuration download - c#

I'm trying to write some software in C# VS which is going to be used to connect through SSH to network devices ( Cisco Switches / Routers ) and download their configuration periodically. I've already tried SharpSSH, SSH.NET. The former is outdated and bugged, the latter just spams exceptions. What I did manage to do is use plink through the Process class to log into the device. Using redirected IO I even managed to print out the configuration. Unfortunately it doesn't print out in full. After a couple of lines a control line stops the output and waits for input
R1#show running-config
Building configuration...
Current configuration : 890 bytes
!
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname R1
!
boot-start-marker
boot-end-marker
!
enable secret 5 $1$Or0j$2.HDFSXaC9jh/KGxhyl6I1
!
no aaa new-model
memory-size iomem 5
ip cef
!
!
!
!
no ip domain lookup
--More--
Like so. It seems like it's a console issue since I turned the feature to output without waiting on on the device. Sending anything at that moment i just like sending a command to the device so I can't actually ask for MORE output ( or at least I haven't found a way ). This may be either the console output issue ( asking whether to output more ) or the StreamWriter going full. My question is: is it possible to turn waiting OFF in a console application? If no - what would you suggest I do? Any ideas are welcome.
kravvcu

Of course you can turn off " --More--". This command will help you (on routers and switches):
R1#terminal length 0
and this one (on Cisco ASA)
terminal pager 0

Use a lightweight TFTP library and use that instead of console downloads?
http://www.codeproject.com/Articles/19314/A-simple-TFTP-client-using-C
If you are set on the console version, just process start a plink connection and read your config off of the process i/o.
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

Related

Autorun console application in linux

I have developed a console application using MVS and I compiled it so can run on linux.
It runs on linux when I manually run and everything works so far. But whenever I try to run it at boot using crontab it seems not to be working.
My application is a HttpListener. The linux environment I run this is a robot's. I've not used linux very much so I have found and used the below commands to get this run at boot.
#reboot /home/rauman/Downloads/webserver
Then I tried setting a delay of 20secs,
#reboot sleep 20 && /home/rauman/Downloads/webserver
I normally run this application with terminal like below and works fine
./webserver
I'm accessing the robot using putty
After adding this to run at boot, I could see the pid of the application,
pidof webserver
So I guess it runs, but got no permission or something?
I have given permission for the file using,
chmod +x webserver
Any help is appreciated.
Edit : Solved
As, Mr. R pointed out
#reboot sleep 20 && cd /home/rauman/Downloads/ && /.webserver
I ran into the same problem a few days ago. My app runs flawlessly when I call it from its working directory but it failed when getting called from outside. It turned out the app reads a file by a relative address. So I had to change either the program or the pwd.
The easiest way that I came by is changing pwd:
#reboot sleep 20 && cd /home/rauman/Downloads/ && ./webserver
crontab runs processes as root, so any another file (such configurations) beloning to your user profile folder cannot be accessibile by ¢rotab.
Is this you scenario?
If yes, you should them into /etc or into /root.

RaspberryPi bluetooth le application always asks for pairing on iOS

Im currently working on a Mobile application which connects to a Ble peripheral and reads data from it. In order to test if the connection is working. I have written a small C# application that utilizes the RaspberryPi4 bluetooth via DBus with BlueZ.
Everything works except that when connecting to iOS a pairing request is issued by the raspberry, eventhough I do not have any encrypted characteristics.
I have read on the Apple forum that this is because bluetoothd is automaticly trying to read the battery level of the phone. But sadly even after the fix suggested there I get the pairing requests.
Does anyone have an idea how I could fix this?
Thanks in advance
I believe disabling this bluez config option in /etc/bluetooth/main.conf would prevent the pi from trying to read characteristics from the iOS device, if that is the issue:
# Do reverse service discovery for previously unknown devices that connect to
# us. For BR/EDR this option is really only needed for qualification since the
# BITE tester doesn't like us doing reverse SDP for some test cases, for LE
# this disables the GATT client functionally so it can be used in system which
# can only operate as peripheral.
# Defaults to 'true'.
#ReverseServiceDiscovery = true
Check the connection min and max intervals, they shall be compliant with the iOS guidelines: https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf (page 180 - 40.6 Connection Parameters).
You can tune them like this:
echo "30" > /sys/kernel/debug/bluetooth/hci0/conn_min_interval
echo "45" > /sys/kernel/debug/bluetooth/hci0/conn_min_interval
The default values worked for me: [24,40]

Windows CE - RegisterWindowMessage WM_DECODEDATA doesn't work

I'm working on simple application for windows CE to scan barcodes.
I have device: CP9700 and this document: 9700 .NET Programming
There is a simple application which implememt barcode scanner in Appendix II (pages 277 and 278).
I have prepared project in VS2008 and copied program from appendix II.
When I run it on my device I can't catch "WM_DECODEDATA" message.
Can anybody tell me what I'm doing wrong ?
First check the return value of RegisterWindowMessage (see https://msdn.microsoft.com/en-us/library/windows/desktop/ms644947%28v=vs.85%29.aspx for details), if it is 0 you need to use Marshal.GetLastWin32Error() (from System.Runtime.InteropServices) to get an error code. The error codes can be looked up in winerror.h of the installed WMx SDK.
The basic sampe app does not check return codes :-((
YOU should check the InitReader return code (see page 22 of the doc).
Please also check if the DLLs are being copied.
The following happens when decoded data comes about,
A decode event broadcasts when the reader decodes data.
The thread waits for the decode event, and the decode data can then
be obtained.
For example,
while(true) {
dwStatus = WaitForSingleObject(handleEvent,INFINITE)
b1 = Reader.ReaderEngineAPI.GetDecodeType();
b1 = Reader.ReaderEngineAPI.GetDecodeData(ref tmp, tmp.length());
}
Reader DLLs are accessible within the OS directory at the following
paths. Before developing your applications, copy the necessary files
from the mobile computer via ActiveSync connection.
\Windows\Reader_Ce_Net.dll
\Windows\ReaderDll_CE.dll

SSH command from C# client redirecting files

The original Unix implementation simply did something like this:
ssh [batchname] < [inputfilename] > [outputfilename]
I need to be able to do the same thing from a windows machine running an application written in C#. I've tried using SharpSsh, which includes input and output streams, but they don't seem to work.
How can I pipe the input and output files/streams using SharpSsh (or any other .Net library)?
Figured it out. Either the application running or SSH itself expects a ctrl-d to signal the end of the input. At that point, the output stream can be read without hanging.

.NET Library for Client/Server application?

I have a plan to write a small "Network manager" for my company using C#. It like a chat application. Please see example bellow:
Ex: Client(C) is manager, Server(S)
C: send string "is_process_running x.exe" (check x.exe is running on server pc)
S: check and send to C: "x.exe is running\nPath: 'C:\\windows\system32\x.exe'"
C: "kill_process_with_warning x.exe"
S: Show a message "Administrator detected you 're running a program that disallowed on computer. It will be kill in 10 seconds" and S kill process x.exe. Reply to C: "process killed!"
C: "disconnect"
...
...
...
I finding library for that. Please tell me something you know about that.
Thanks !
Use a TcpClient and TcpListener.
Is there any reason you wouldn't use WCF?
It may be an overkill for what you described here, but such apps are bound to grow in order to add funcionality.
It does have a great lot of abilities, but here's a quickstart guide.

Categories