3 Replies - 1007 Views - Last Post: 04 September 2011 - 04:24 AM Rate Topic: -----

#1 rajeshjayaswar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-September 11

ryby nokogiri

Posted 02 September 2011 - 05:08 AM

<port protocol="tcp" portid="22">
<state state="open" reason="syn-ack" reason_ttl="64"/>
<service name="ssh" product="OpenSSH" version="3.9p1" extrainfo="protocol 2.0" method="probed" conf="10"/>
<script id="ssh-hostkey" output="1024 89:eb:87:05:f2:3e:6b:66:1f:7e:3f:87:df:cf:e1:64 (DSA)&#xa;ssh-dss AAAAB3NzaC1kc3MAAACBAOostKzFdV9zaDlhiuwzi1G4RS/0yetecLwgfYS8Ra1frnc74We965Jc68gnPMCDEiQPICtq5B15pvzcUOr6QFgiQQH6jk5Ms+9popv4RdC7Sz7tHCJt7e6tBjjtsAazmX6ciwNWxy5UHDwUUrD+ck8TbhSh7ZDcz9kIyfMFzVhRAAAAFQDIrSDwn3m0kJyQ3Fba60caSWx4zQAAAIBKhAvH6jLXc0+hD2gZScwuODGCGIf0r9ulvVGChpxx7s9Dx5ah4WtULaLY1ZC22g7b5Y38w436FS21jNgrTEJIhpms7cN5vu9mcFEeMrkyzV4RoLNX8czPV6hguRFCjO6uisFFdjAjs++2ojL0zX380Sm5J50th4uQXVfd+mf+vQAAAIEA6YDXVl1M7t+wVHjkcTqEHXyFioajOu9aBW3hAjbV/0Sarj+JkuJ7d038OvVgJa6VJfK2tq9IPtHJy+A1zVueJEFHfVbOIvWT62ZzjoHl6/y3SAnaxc7S4S7k0gGtoiZISHlBVbVwOXhe36AZ7fSsUYMhJS0eBDidOgfgzyb0zro=&#xa;1024 51:e0:01:9f:3a:2b:d1:b6:6c:15:77:ca:29:bd:72:dd (RSA)&#xa;ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAnl24hjGxfaGud4fFXvkC/3qDsg7qbKXbp92mABxkXLoZtH7719VoM/2+D+947PHMvtiQvLG8QuThKgDiqkP/KC+v5sL1s+CYx9kxgkWruV9r0As3d3oYAPt1LvyUSin+q0/Nl+5iCo0UxS/4sRT7Hz0+cE5aUOls7+4VH3DeF/c="/>
</port>

<port protocol="tcp" portid="80">
<state state="open" reason="syn-ack" reason_ttl="64"/>
<service name="http" product="Apache Tomcat/Coyote JSP engine" version="1.1" method="probed" conf="10"/><script id="http-methods" output="No Allow or Public header in OPTIONS response (status code 400)"/>
</port>
<port protocol="tcp" portid="111">
<state state="open" reason="syn-ack" reason_ttl="64"/><service name="rpcbind" version="2" extrainfo="rpc #100000" method="probed" conf="10" rpcnum="100000" lowver="2" highver="2" proto="rpc"/>
</port>
<port protocol="tcp" portid="443">
<state state="open" reason="syn-ack" reason_ttl="64"/><service name="http" product="Apache httpd" version="2.2.18" extrainfo="(Unix) mod_ssl/2.2.18 OpenSSL/0.9.8k" tunnel="ssl" method="probed" conf="10"/><script id="http-title" output="302 Found&#xa;Did not follow redirect to https://10.200.204.10/vodafone/"/><script id="http-methods" output="No Allow or Public header in OPTIONS response (status code 302)"/>
</port>
<port protocol="tcp" portid="632">
<state state="open" reason="syn-ack" reason_ttl="64"/><service name="status" version="1" extrainfo="rpc #100024" method="probed" conf="10" rpcnum="100024" lowver="1" highver="1" proto="rpc"/>
</port>
<port protocol="tcp" portid="7777">
<state state="open" reason="syn-ack" reason_ttl="64"/><service name="tcpwrapped" method="probed" conf="8"/>
</port>
<port protocol="tcp" portid="7890">
<state state="open" reason="syn-ack" reason_ttl="64"/><service name="tcpwrapped" method="probed" conf="8"/>
</port>
<port protocol="tcp" portid="8080">
<state state="open" reason="syn-ack" reason_ttl="64"/><service name="http" product="Apache Tomcat/Coyote JSP engine" version="1.1" method="probed" conf="10"/><script id="http-methods" output="No Allow or Public header in OPTIONS response (status code 400)"/>
</port>
<port protocol="tcp" portid="8081">
<state state="open" reason="syn-ack" reason_ttl="64"/><service name="http" product="Apache httpd" version="2.2.18" extrainfo="(Unix) mod_ssl/2.2.18 OpenSSL/0.9.8k" method="probed" conf="10"/><script id="http-title" output="Site doesn&apos;t have a title (text/html)."/><script id="http-methods" output="GET HEAD POST OPTIONS TRACE&#xa;Potentially risky methods: TRACE&#xa;See http://nmap.org/nsedoc/scripts/http-methods.html"/>
</port>
<port protocol="tcp" portid="8443">
<state state="open" reason="syn-ack" reason_ttl="64"/><service name="http" product="Apache httpd" extrainfo="SSL-only mode" method="probed" conf="10"/><script id="http-methods" output="No Allow or Public header in OPTIONS response (status code 302)"/>
</port>


(THIS IS NMAP.XML FILE)


I WANT TO READ THIS FILE AND WANT OUTPUT IN THIS FORMAT :
tcp 22 / ssh / open
tcp 80 / http / open
.
.
.

I WROTE CODE FOR THIS BUT IT DOSE NOT WORKS PROPERLY:
require 'nokogiri'
xml=Nokogiri::XML File.open 'nmap.xml'
xml.xpath('//port | //service | //state  ').each  {|node| puts "#{ node['protocol'] } / #{ node['portid'] } #{ node['state'] } #{node['name']}  "}


WHAT IS SHOULD MODIFY TO GET THE DESIRE RESULT.

THAN YOU.

This post has been edited by macosxnerd101: 02 September 2011 - 05:54 AM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: ryby nokogiri

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10183
  • View blog
  • Posts: 37,596
  • Joined: 27-December 08

Re: ryby nokogiri

Posted 02 September 2011 - 05:54 AM

What specific problems or errors are you encountering?
Was This Post Helpful? 0
  • +
  • -

#3 rajeshjayaswar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-September 11

Re: ryby nokogiri

Posted 02 September 2011 - 11:02 AM

View Postmacosxnerd101, on 02 September 2011 - 05:54 AM, said:

What specific problems or errors are you encountering?


i am getting output in this format:

tcp 22 /
/ open
/ssh
tcp 80 /
/ open
/ http
.
.
.
Was This Post Helpful? 0
  • +
  • -

#4 Skaggles  Icon User is offline

  • THE PEN IS MIGHTIER
  • member icon





Reputation: 251
  • View blog
  • Posts: 640
  • Joined: 01-March 09

Re: ryby nokogiri

Posted 04 September 2011 - 04:24 AM

If it's just a problem of having line breaks at the end of strings, you can do a chomp! on them:

    puts "#{node['protocol'].chomp!} / #{node['portid'].chomp!}"



chomp! will removed the characters from the end of a string that you specify if they exist. If you don't specify any characters, it will just remove any trailing \r\n instead.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1