in reply to Re^2: Telnet list of IP and get information stored to a file
in thread Telnet list of IP and get information stored to a file
To make the output go to the "telnet.log" file handle, you need to tell the print statement to use the file handle! For instance, change:
print "Bad connection.\n";to
print OUT "Bad connection.\n";...roboticus
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Telnet list of IP and get information stored to a file
by sanju7 (Acolyte) on Jul 29, 2010 at 01:28 UTC | |
Roboticus: Thanks for reply, i think i am just overwhelmed of the obstacles to achieve the task. I have some success in the form of basic structure of the script and logic --however few more steps to go. Here is the code doing the job. Success: The code iterates through a text file (list of ip addresses) and telnets to the specific port and logs the error Issues: (a) The code for some reason doesn't logs the message when its success. When tested with a single IP its logging successfully though. (b) I am not getting how to expand an ip address which is a network (eg:10.3.3.0/24). This would make the code successfully iterate through most of the org servers if not all (assuming some of them have different network setup, firewall etc) The below code is the basic structure working fine but not picking the success when run on a list
The file iplist1.txt as below
This populates recordlog.txt only as below
When i tested with single ip the code seems to populate dumplog file giving me some idea as to what return values i am dealing with even though I am still looking why it doesn't log to the outputlog or inputlog or optionslog. The following test code i used to populate the dumplog
This is the screendump as below
This is how the dumpfile looks as below
Using telnet and interacting with it even with its very basic form needs understanding of how the application is responding to the telnet request etc. The application i am querying is kind of like SMTP service. It doesn't has a prompt or so ..thats how i deviced my code on both the scripts above matching with ('//') and trying to "put" a carriage return to the main "$telnet" object. If you have any suggestion here please let me know. I am dumping the app behavior for your understanding as below
Usually on success within 30 second the telnet connection disconnects dumping the nodename and that is what i need. From the many servers around the spread out internal network this seems easiest to spot the server with that particular app, app only responds to telnet and won't otherwise (tried nmap not sure if i did correct enough switch etc though). Your expert suggestion to complete script /resolve both the issue will help me a lot. | [reply] [d/l] [select] |
by roboticus (Chancellor) on Jul 29, 2010 at 06:16 UTC | |
(a) The code for some reason doesn't logs the message when its success. When tested with a single IP its logging successfully though. You're not being very specific on *which* log isn't updated. Looking at your code, I can think of several possibilities: (b) I am not getting how to expand an ip address which is a network (eg:10.3.3.0/24). There are lots of ways to do it. For the example you give, 10.3.3.0/24, the first 24 bits of the address should remain a constant: 10.3.3, and you should vary the last eight bits through the values 1..255. So first you need to detect that your address needs to be expanded, then figure out which part(s) of the address need to vary, and then generate the appropriate sequence. So the code that does the work on an IP address should be in a subroutine. Then you can call it in a loop for each address in the expansion. I get the feeling that you're trying to bite off too much at a time. You might consider breaking your project into distinct chunks, and solve each chunk individually. ...roboticus | [reply] [d/l] |
by sanju7 (Acolyte) on Jul 30, 2010 at 16:52 UTC | |
Roboticus You may be referring to the print "connected" message, in which case you're not telling it to go to a log file, like you are for the failures. Indeed i am referring that, more preciously I need to record this as below like a success message, because telnet gives this why the script cann't get this ? dds_pc: _ms=nodecc.dom.org.localþ_si=Process controllerþ_mid=9016þ_sev +=0þ_dt=2010/07/29þ_tm=01:12:02þ_pkg=þbut instead the only reply i am getting is ("The server returned: 1") , The server returned: 1 The server returned: 1 The server returned: 1 Bad connection - Unable to connect to IP 3.xx.yy.zz at ------------------- Bad connection - Unable to connect to IP 3.xxx.yyy.zz at ------------------- Bad connection - Unable to connect to IP 3.xxx.yyy.y at -------------------- | [reply] |
by rowdog (Curate) on Aug 01, 2010 at 11:26 UTC | |