469,315 Members | 2,189 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

How to detect remote machine os, while connecting?

10
Hi,

How to detect remote machine os, while connecting?
I want to find out remote machine os is windows/unix/linux/solaries, without login into the machine, while connecting itself.


Thanks
srikanth
Sep 25 '12 #1
17 5894
RonB
589 Expert Mod 512MB
You need to provide more details on what you need to accomplish and in what context is the user connecting. Is this connection via a network share, or a web service, or RDP or telnet or ssh or something else?

You will probably also need to post your script and any errors/warnings that it generates.
Sep 25 '12 #2
ckant8
10
Hi Ron,

I am connecting hosts via Telnet. So can u guide me how to know the host's os.

Thanks
srikanth
Sep 26 '12 #3
numberwhun
3,503 Expert Mod 2GB
Are you saying that your using telnet from the system command in Perl, from a Perl Module, or are you using telnet on the command line without the use of Perl? You need to please specify.

If you are using Perl for this, then you NEED to please provide your code, otherwise we will be grasping at straws, blindly.

Regards,

Jeff
Sep 26 '12 #4
ckant8
10
Here is the code i use to connect host using telnet.

1. use Net::Telnet;
2. $telnet = new Net::Telnet ( Timeout=>60, Errmode=>'die');
3. $telnet->open('10.xxx.xxx.xxx'); # unix/win/linux/sun
4. $telnet->waitfor('/login: $/i');
5. $telnet->print('administrator'); # root/administrator
6. $telnet->waitfor('/password: $/i');
7. $telnet->print('admin');
8. $telnet->waitfor('/\>/'); # '/\>/'--win, '/# $/i' - unix

I need to know the os of host, before i login. at step 3.
so that i will write my own code to perform as per the os. bcz
"telnet->waitfor('/\>/');" is differ for os.

Thanks
srikanth
Sep 26 '12 #5
ckant8
10
using eclipse i am executing perl code.
Sep 26 '12 #6
RonB
589 Expert Mod 512MB
You can't use telnet to determine the OS prior to login, but you can use the nmap utility to scan the host and determine the OS. However, keep in mind that there is no reliable way to accurately determine the OS prior to logging into the system.

nmap network scanner:
http://nmap.org/

Perl module to interface with nmap:
Nmap::Scanner

Output from a scan of google.com
C:\Users\RKB>nmap -O -sSU google.com

Starting Nmap 5.21 ( http://nmap.org ) at 2012-09-26 06:28 Pacific Daylight Time
Nmap scan report for google.com (74.125.224.105)
Host is up (0.0028s latency).
Hostname google.com resolves to 11 IPs. Only scanned 74.125.224.105
rDNS record for 74.125.224.105: nuq04s08-in-f9.1e100.net
Not shown: 998 filtered ports, 998 open|filtered ports
PORT STATE SERVICE
80/tcp open http
113/tcp closed auth
443/tcp open https
33459/udp closed unknown
Device type: WAP|printer|webcam|general purpose
Running (JUST GUESSING) : Linksys Linux 2.4.X (87%), Lexmark embedded (87%), AXIS Linux 2.6.X (87%), Linux 2.6.X|2.4.X (86%)
Aggressive OS guesses: OpenWrt White Russian 0.9 (Linux 2.4.30) (87%), Lexmark X644e printer (87%), AXIS 211A Network Camera (Linux 2.6) (87%), AXIS 211A Network Camera (Linux 2.6.20) (87%), OpenWrt Kamikaze 7.09 (Linux 2.6.2
2) (86%), Linux 2.6.24 (86%), OpenWrt 0.9 - 7.09 (Linux 2.4.30 - 2.4.34) (85%), Linux 2.4.20 - 2.4.27 (85%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 14 hops

OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 13.47 seconds
Sep 26 '12 #7
ckant8
10
i hear that we can use socket function also to check os. if any help in this, it would be helpful for my script.
Sep 26 '12 #8
RonB
589 Expert Mod 512MB
Yes you can make a low level socket connection to a service running on the remote server (which is what Net::Telnet does). You need to decide which service you want/need to connect to which will give you the info you want.

Socket - networking constants and support functions
IO::Socket - Object interface to socket communications
Sep 26 '12 #9
ckant8
10
can you give simple code to check host os.
Sep 27 '12 #10
RonB
589 Expert Mod 512MB
Sorry, I don't know of any server service that would easily give you the OS, so I can't give you what you want.

The nmap utility tries to "guess" the OS by looking at key "footprints", but I have no idea how they do that, however nmap is open source, so you can look at it's source code to try to find out how they attempt to discover the OS.

Why is it so important for you to know the OS prior to login?

If you're able to login via telnet, then it would be simple to execute a command to learn that info.
Sep 27 '12 #11
ckant8
10
if i know the os, then i will login to specified host and write my code individually. because commands are differ from win to unix. commands are simple - diskpart,...
Sep 27 '12 #12
RonB
589 Expert Mod 512MB
Then the simple solution would be to put the OS specific code into subroutines and AFTER you login, you determine the OS and then execute the proper subroutine.
Sep 27 '12 #13
RonB
589 Expert Mod 512MB
The more I read over your posts, the more it appears to me that you're attempting to write some sort of malware.
Sep 27 '12 #14
ckant8
10
Hi RonB,

If you see my code above, if i know the host os with that i can recognize(windows command prompt - >, unix - $) the host type and then i can proceed my code as per. For my job needs username(step 5) needs only administrator for windows and root for unix/linux. so if i know it before i will go straight.
Sep 27 '12 #15
ckant8
10
After i connect, i have to give username. There i need to know the OS type. Based on that i will give username.
Sep 27 '12 #16
RonB
589 Expert Mod 512MB
You're not going to be able to determine the OS prior to login.
Sep 27 '12 #17
RonB
589 Expert Mod 512MB
Here's an example demonstrating the fact that you won;t be able to accurately determine the OS.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use 5.10.1;
  4. use strict;
  5. use warnings;
  6. use XML::Simple;
  7. use Data::Dumper;
  8.  
  9. close STDERR;
  10.  
  11. foreach my $ip ( qw(10.100.0.130 10.100.0.119 10.100.0.118) ) {
  12.     say "scanning $ip";
  13.     say '-' x 21;
  14.     my $nmap = `nmap -v -v -v -O  -oX - $ip`;
  15.     my $nmap_xml = XMLin($nmap);
  16.     say Dumper keys %{ $nmap_xml->{host}{os}{osmatch} };
  17. }
  18.  
Outputs:
scanning 10.100.0.130
---------------------
$VAR1 = 'name';
$VAR2 = 'accuracy';
$VAR3 = 'line';

scanning 10.100.0.119
---------------------

scanning 10.100.0.118
---------------------
$VAR1 = 'AXIS 211A Network Camera (Linux 2.6.20)';
$VAR2 = 'Linux 2.6.17 (Mandriva)';
$VAR3 = 'Linux 2.6.9 - 2.6.18';
$VAR4 = 'Linux 2.6.22 - 2.6.23';
$VAR5 = 'IBM System Storage DS4700 NAS device';
$VAR6 = 'Linux 2.6.9 - 2.6.27';
$VAR7 = 'Linux 2.6.9 - 2.6.28';
$VAR8 = 'Linux 2.6.28 (Gentoo)';
$VAR9 = 'AXIS 211A Network Camera (Linux 2.6)';
$VAR10 = 'Linux 2.6.18 (Centos 5.3)';
All 3 of those hosts are on the local network.

Can you tell me the OS for the first 2 and which one of those 10 results for the 3rd host is correct?
Sep 27 '12 #18

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by McGeeky | last post: by
4 posts views Thread by Rohith | last post: by
4 posts views Thread by Chris Johnson | last post: by
7 posts views Thread by Chris Marsh | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.