I am using ruby script to send commands to the UT. I have successfully established telnet session to the remote UT. The commands sent perform series of operation and gives me the statistics.
Initially, after successfully sending the command, I designed UT to send an OK to script which is received. How do I receive the statistics information? The script doesn't know the output of command in advance and each command will have its own string.
Using ruby, how can I tell telnet::waitfor() command to wait for so long duration but break out if UT sends something.?
To read the OK, i used:
response=#newSession.waitfor({"String" => "OK\n", "Timeout" => time_out})
where, newSession holds the telnet session connection.
#newSession = Net::Telnet::new("Session" => #session,
"Host" => #ut_ip,
"Port" => #port_num,
"Timeout" => 10,
"Prompt" => /[$%#>] \z/n)
I cant use "Match" or "Prompt" since I don't know what I am gonna get.! Help me out guys.. Thanks.
Let’s read the documentation on Net::Telnet:
For some protocols, it will be possible to specify the Prompt option once when you create the Telnet object and use cmd() calls; for others, you will have to specify the response sequence to look for as the Match option to every cmd() call, or call puts() and waitfor() directly; for yet others, you will have to use sysread() instead of waitfor() and parse server responses yourself.
So, you are about to handle the IO yourself and #preprocess it.
Related
I am using an AWS webserver, which is being polled by some other script. The problem is that when I start the server twice in a few seconds (with requests of a client in between), the server fails to start again, saying:
raised AWS.NET.SOCKET_ERROR : Bind : [98] Address already in use
There is this old thread that suggests there may be a reuse_address
option, either in a ini file or as a direct parameter, but says that that also does not work.
Perhaps there is some way to force the OS to abandon the socket?
You need to call AWS.Config.Set.Reuse_Address (Config, True); or set it in the AWS ini file.
For example:
with AWS.Config;
with AWS.Config.Set;
(...)
declare
HTTP_Server : AWS.Server.HTTP;
AWS_Config : AWS.Config.Object := AWS.Config.Default_Config;
begin
AWS.Config.Set.Reuse_Address (AWS_Config, True);
AWS.Config.Set.Server_Port (AWS_Config, 80);
AWS.Server.Start (HTTP_Server, Callback => Respond'Unrestricted_Access, Config => AWS_Config);
(...)
Using a Raspi/Debian - I have a script that parses the results from an iwlist scan and sends them via UDP to a Pure Data patch. This runs fine in gui mode, but now I'm trying to automate the whole process in another script with the following:
pd-extended -nogui /home/pi/patch.pd & /home/pi/libOSC/scan.sh && fg
But when I run this new script, the UDP appears to only send the info to Pure Data once, and then the scanning continues but Pd does not receive the packet. Any help with this would be appreciated.
What happens when you run /home/pi/libOSC/scan.sh? It sends the results only once? Then maybe you need to do it differently, like calling that script from within pd using the 'shell' or 'popen' objects for instance. Or you implement a polling command via UDP that will return the values.
how does your scan.sh script look like?
you probably want to make it something like:
pdhost=localhost
pdport=9999
do_scan() {
## some code here that does the scan and print's the result to stdout
}
doscan | while read line
do
echo "${line};" | pdsend ${pdhost} ${pdport}
done
rather than the following:
doscan | pdsend ${pdhost} ${pdport}
I've been struggling a lot these last few days with a FTPS server that requires the 'CCC' command I'm trying to access via .Net
I'm using AlexFTPS Library. I'm able to connect and negociate AUTH TLS, I'm able to change directory but when I'm trying to list directory or download files, server asks for 'CCC' command. When I send 'CCC' command, I get a '200 CCC Context Enabled' reply but then I cannot send anything else, anytime I get a server timeout exception.
I've done further tests :
WS_FTP : works if I check the 'Use unencrypted command channel after SSL authentication' option
Filezilla : does not work even if I add 'CCC' as a Post Login Command
http://www.componentpro.com/ftp.net/ : works but is not open source
Any help would be so much appreciated... Sorry I am not FTP fluent...
Here's my code :
Using Client As New AlexPilotti.FTPS.Client.FTPSClient
AddHandler Client.LogCommand, Sub(sender As Object, args As AlexPilotti.FTPS.Common.LogCommandEventArgs)
Console.WriteLine(args.CommandText)
End Sub
AddHandler Client.LogServerReply, Sub(sender As Object, args As AlexPilotti.FTPS.Common.LogServerReplyEventArgs)
Console.WriteLine(args.ServerReply)
End Sub
Dim cred = New Net.NetworkCredential("login", "password")
Client.Connect("ftps.server.com", cred, AlexPilotti.FTPS.Client.ESSLSupportMode.CredentialsRequired)
Client.SendCustomCommand("SYST")
Client.SendCustomCommand("PBSZ 0")
Client.SendCustomCommand("PROT P")
Client.SendCustomCommand("FEAT")
Client.SendCustomCommand("PWD")
Client.SendCustomCommand("TYPE A")
Client.SendCustomCommand("PASV")
Client.SendCustomCommand("CCC")
Client.SendCustomCommand("LIST")
Console.ReadKey()
End Using
Thanks !
CCC ("Clear Command Channel") is a special command which downgrades the connection from SSL (started with AUTH TLS) back to unencrypted again. So it's no enough to just declare it as a custom command which gets send on the established control connection, it has to be handled similar to AUTH TLS by the FTPS library so that after the command is done the TLS downgrade occurs.
I'm attempting to create a script in ruby that connects to a Minecraft server via TCP and fetches the current number of players much like the PHP script at http://www.webmaster-source.com/2012/07/05/checking-the-status-of-a-minecraft-server-with-php/
When running the code below I get �Took too long to log in
require 'socket'
server = TCPSocket.new '192.241.174.210', 25565
while line = server.gets
puts line
end
server.close
What am I doing wrong here?
you're not sending this:
fwrite($sock, "\xfe");
from the script you linked. You have to send that before you call read, like they do.
Basically the server is waiting for you to send data and when you don't after a timeout, you are disconnected.
I'm attempting to use Ruby SNMP to capture SNMP traps from various devices. In order to test them I'm attempting to send them from my laptop using the 'snmptrap' command. I can see that the traps are being sent and arriving at my server (the server is the manager) in packet captures, as well as in the 'snmptrapd' utility when I run it. I'm using the following example code exactly as it is, in the demo from the documentation to set up a TrapListener.
require 'snmp'
require 'logger'
log = Logger.new(STDOUT)
m = SNMP::TrapListener.new do |manager|
manager.on_trap_default do |trap|
log.info trap.inspect
end
end
m.join
I'm sending an SNMPv2c trap, and nothing ever appears on the screen...
Here is the command I'm using to send a test SMTP trap, in the even that it's useful:
snmptrap -v 2c -c public hostname_goes_here SNMP-NOTIFICATION-MIB::snmpNotifyType SNMPv2-MIB::sysLocation
Any suggestions appreciated! Thanks!
I was stuck on this for a long time as well. It turns out that by default, Traplistener only opens ports on 127.0.0.1. To make it listen on ALL interfaces on the port you specified (or default port 162), specify a :Host option. '0' makes it listen on ALL interfaces, or you can provide an IP address.
log = Logger.new(STDOUT)
m = SNMP::TrapListener.new(:Host => 0) do |manager|
manager.on_trap_default do |trap|
log.info trap.inspect
end
end
m.join