少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          #

          首先下載一個redis的安裝包:

          windows:http://code.google.com/p/servicestack/wiki/RedisWindowsDownload

          linux:http://code.google.com/p/redis/downloads/list

          redis-2.0.0版本: redis-2.0.0 (302)

          redis-2.4.5版本: redis-2.4.5-win32-win64.zip (506)

          解壓后,得到一個redis的文件夾,打開文件夾得到如下圖的一些文件:

          安裝包中是不提供redis.conf的,關于配置可以到網上搜索一下,或者從這里直接下載:redis.conf (643)

          下載后可以將redis.conf放到上圖所示位置!

          用命令行,切換到redis的根目錄,然后啟動redis服務端即redis-server.exe,如下圖:

           

          啟動后的效果圖如下:

          當前服務端沒有1個客戶端連接,因此顯示0 clients,

          現在分別啟動兩個客戶端,如下圖:

          這里值得注意的是:當你登錄redis-cli.exe的時候,服務端并沒有檢測到客戶端的存在,也就是在客戶端執行了第一次操作以后,服務端才檢測到這個狀態.

















          posted @ 2012-11-12 20:44 abin 閱讀(2929) | 評論 (0)編輯 收藏

          package lc.abin.lee.basic.zip;

          import java.io.BufferedOutputStream;
          import java.io.BufferedReader;
          import java.io.FileOutputStream;
          import java.io.FileReader;
          import java.util.zip.CRC32;
          import java.util.zip.CheckedOutputStream;
          import java.util.zip.ZipEntry;
          import java.util.zip.ZipOutputStream;

          public class CreateZip {
           public static String createZipFile(String filePath){
            String result="failure";
            try {
             FileOutputStream fileOut=new FileOutputStream("example.zip");
             CheckedOutputStream checkOut=new CheckedOutputStream(fileOut,new CRC32());
             ZipOutputStream zipOut=new ZipOutputStream(new BufferedOutputStream(checkOut));
             
             BufferedReader in=new BufferedReader(new FileReader(filePath));
             zipOut.putNextEntry(new ZipEntry(filePath));
             int line;
             while((line=in.read())!=-1){
              zipOut.write(line);
              zipOut.flush();
             }
             result="success";
             in.close();
             zipOut.close();
            } catch (Exception e) {
             e.printStackTrace();
            }
            return result;
           }
           public static void main(String[] args) {
            String fileName="D:\\abin.txt";
            String result=createZipFile(fileName);
            System.out.println("result="+result);
           }
          }



          貌似還有點問題,明天解決一下
          posted @ 2012-11-11 23:32 abin 閱讀(424) | 評論 (0)編輯 收藏

          學習了memcache,這是個好東西,分享一下自己的小實例,也方便以后查找使用

          一、前期準備

          1)  下載memcached服務端memcached-1.2.6-win32-bin.zip,地址:http://code.jellycan.com/memcached/

          2)  下載java版客戶端 java_memcached-release_2.6.1.zip
          3)  解壓縮memcached-1.2.6-win32-bin.zip到指定目錄,例如:D:\memcached-1.2.6-win32 ,在終端(即cmd命令行界面)
           
          D:\memcached-1.2.6-win32\memcached.exe -d install
          D:\memcached\memcached.exe -d start
           
          這樣memcache就會作為windows系統服務在每次開機時啟動memcache服務。
           
          常用命令
           
          -p 監聽的端口 
          -l 連接的IP地址, 默認是本機 
          -d start 啟動memcached服務 
          -d restart 重起memcached服務 
          -d stop|shutdown 關閉正在運行的memcached服務 
          -d install 安裝memcached服務 
          -d uninstall 卸載memcached服務 
          -u 以的身份運行 (僅在以root運行的時候有效) 
          -m 最大內存使用,單位MB。默認64MB 
          -M 內存耗盡時返回錯誤,而不是刪除項 
          -c 最大同時連接數,默認是1024 
          -f 塊大小增長因子,默認是1.25 
          -n 最小分配空間,key+value+flags默認是48 
          -h 顯示幫助 



          spring-memcache.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
              xmlns:cache
          ="http://www.springframework.org/schema/cache"
              xmlns:context
          ="http://www.springframework.org/schema/context"
              xmlns:mvc
          ="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
              xmlns:p
          ="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
              xsi:schemaLocation
          ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
              http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd  
              http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd  
                 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                 http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">

              
          <bean id="memcachedPool" class="com.danga.MemCached.SockIOPool"
                  factory
          -method="getInstance" init-method="initialize" destroy-method="shutDown">
                  
          <constructor-arg>
                      
          <value>neeaMemcachedPool</value>
                  
          </constructor-arg>
                  
          <property name="servers">
                      
          <list>
                          
          <value>127.0.0.1:11211</value>
                      
          </list>
                  
          </property>
                  
          <property name="initConn">
                      
          <value>20</value>
                  
          </property>
                  
          <property name="minConn">
                      
          <value>10</value>
                  
          </property>
                  
          <property name="maxConn">
                      
          <value>50</value>
                  
          </property>
                  
          <property name="maintSleep">
                      
          <value>3000</value>
                  
          </property>
                  
          <property name="nagle">
                      
          <value>false</value>
                  
          </property>
                  
          <property name="socketTO">
                      
          <value>3000</value>
                  
          </property>
              
          </bean>
              
              
          <bean id="memcachedClient" class="com.danga.MemCached.MemCachedClient">
                  
          <constructor-arg>
                      
          <value>neeaMemcachedPool</value>
                  
          </constructor-arg>
              
          </bean>
              

          </beans>






          測試類:

          package com.abin.lee.spring.memcache;

          import org.junit.BeforeClass;
          import org.junit.Test;
          import org.springframework.context.ApplicationContext;
          import org.springframework.context.support.ClassPathXmlApplicationContext;

          import com.danga.MemCached.MemCachedClient;

          public class MemcacheUtilTest {
           static MemCachedClient memcachedClient;
           @BeforeClass
           public static void setUpBeforeClass() throws Exception {
            ApplicationContext context= new ClassPathXmlApplicationContext("com/abin/lee/spring/memcache/spring-memcache.xml");
            memcachedClient= (MemCachedClient)context.getBean("memcachedClient");
           }

           @Test
           public void test() {
            memcachedClient.set("name", "abin");
            System.out.println(memcachedClient.get("name"));
           }
          }

          posted @ 2012-11-10 22:33 abin 閱讀(1359) | 評論 (1)編輯 收藏

          1. 看到一個題目:針對下面的程序,寫出magic方法 讓整個程序只打印出step1,step2 不打印step3  

              public static void enter(Object obj) {
                  System.out.println("Step 1");
                  try {
             magic1(obj);
            } catch (Exception e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            }
                  System.out.println("Step 2");
                  synchronized (obj) {
                      System.out.println("Step 3 (never reached here)"); 
                  }
              }

           題目的意思很容易理解,可是要做出這道題目需要對多線程的基本改進非常的理解。

          下面列出基本思路:

           

           

          主線程想獲取obj的鎖,但是獲取不到,說明子線程始終在占據著這個對象的鎖。

          同時主線程又能返回。

          那現在就要實現讓子線程先跑,然后再喚醒主線程。這個顯然是鎖的占有和喚醒,那么問題來了,將什么做為這個鎖呢?如果是obj的話,不可能,因為子線程顯然不能在放掉obj.

          那么只能是子線程自己的鎖。

           

          下邊是程序

              static void magic1(final Object obj) throws Exception{
               final Thread t = new Thread(){
                public void run(){
                 synchronized(this){
                  synchronized(obj){
                   try {
                    notify();
                 join();
                } catch (InterruptedException e) {
                }
                  }
                  
                 }
                 
                }
               };
               synchronized(t){
                t.start();
                t.wait();
               }
              }




          posted @ 2012-11-09 21:37 abin 閱讀(357) | 評論 (0)編輯 收藏

          面試hadoop可能被問到的問題,你能回答出幾個 ?

          1、hadoop運行的原理?

          2、mapreduce的原理?

          3、HDFS存儲的機制?

          4、舉一個簡單的例子說明mapreduce是怎么來運行的 ?

          5、面試的人給你出一些問題,讓你用mapreduce來實現?

                比如:現在有10個文件夾,每個文件夾都有1000000個url.現在讓你找出top1000000url。

          6、hadoop中Combiner的作用?

          Src: http://p-x1984.javaeye.com/blog/859843


           

          Q1. Name the most common InputFormats defined in Hadoop? Which one is default ? 
          Following 2 are most common InputFormats defined in Hadoop 
          - TextInputFormat
          - KeyValueInputFormat
          - SequenceFileInputFormat
          Q2. What is the difference between TextInputFormatand KeyValueInputFormat class
          TextInputFormat: It reads lines of text files and provides the offset of the line as key to the Mapper and actual line as Value to the mapper
          KeyValueInputFormat: Reads text file and parses lines into key, val pairs. Everything up to the first tab character is sent as key to the Mapper and the remainder of the line is sent as value to the mapper.

          Q3. What is InputSplit in Hadoop
          When a hadoop job is run, it splits input files into chunks and assign each split to a mapper to process. This is called Input Split 

          Q4. How is the splitting of file invoked in Hadoop Framework 
          It is invoked by the Hadoop framework by running getInputSplit()method of the Input format class (like FileInputFormat) defined by the user 

          Q5. Consider case scenario: In M/R system,
              - HDFS block size is 64 MB
              - Input format is FileInputFormat
              - We have 3 files of size 64K, 65Mb and 127Mb 
          then how many input splits will be made by Hadoop framework?
          Hadoop will make 5 splits as follows 
          - 1 split for 64K files 
          - 2  splits for 65Mb files 
          - 2 splits for 127Mb file 

          Q6. What is the purpose of RecordReader in Hadoop
          The InputSplithas defined a slice of work, but does not describe how to access it. The RecordReaderclass actually loads the data from its source and converts it into (key, value) pairs suitable for reading by the Mapper. The RecordReader instance is defined by the InputFormat 

          Q7. After the Map phase finishes, the hadoop framework does "Partitioning, Shuffle and sort". Explain what happens in this phase?
          - Partitioning
          Partitioning is the process of determining which reducer instance will receive which intermediate keys and values. Each mapper must determine for all of its output (key, value) pairs which reducer will receive them. It is necessary that for any key, regardless of which mapper instance generated it, the destination partition is the same

          - Shuffle
          After the first map tasks have completed, the nodes may still be performing several more map tasks each. But they also begin exchanging the intermediate outputs from the map tasks to where they are required by the reducers. This process of moving map outputs to the reducers is known as shuffling.

          - Sort
          Each reduce task is responsible for reducing the values associated with several intermediate keys. The set of intermediate keys on a single node is automatically sorted by Hadoop before they are presented to the Reducer 

          Q9. If no custom partitioner is defined in the hadoop then how is data partitioned before its sent to the reducer 
          The default partitioner computes a hash value for the key and assigns the partition based on this result 

          Q10. What is a Combiner 
          The Combiner is a "mini-reduce" process which operates only on data generated by a mapper. The Combiner will receive as input all data emitted by the Mapper instances on a given node. The output from the Combiner is then sent to the Reducers, instead of the output from the Mappers.
          Q11. Give an example scenario where a cobiner can be used and where it cannot be used
          There can be several examples following are the most common ones
          - Scenario where you can use combiner
            Getting list of distinct words in a file

          - Scenario where you cannot use a combiner
            Calculating mean of a list of numbers 
          Q12. What is job tracker
          Job Tracker is the service within Hadoop that runs Map Reduce jobs on the cluster

          Q13. What are some typical functions of Job Tracker
          The following are some typical tasks of Job Tracker
          - Accepts jobs from clients
          - It talks to the NameNode to determine the location of the data
          - It locates TaskTracker nodes with available slots at or near the data
          - It submits the work to the chosen Task Tracker nodes and monitors progress of each task by receiving heartbeat signals from Task tracker 

          Q14. What is task tracker
          Task Tracker is a node in the cluster that accepts tasks like Map, Reduce and Shuffle operations - from a JobTracker 

          Q15. Whats the relationship between Jobs and Tasks in Hadoop
          One job is broken down into one or many tasks in Hadoop

          Q16. Suppose Hadoop spawned 100 tasks for a job and one of the task failed. What willhadoop do ?
          It will restart the task again on some other task tracker and only if the task fails more than 4 (default setting and can be changed) times will it kill the job

          Q17. Hadoop achieves parallelism by dividing the tasks across many nodes, it is possible for a few slow nodes to rate-limit the rest of the program and slow down the program. What mechanism Hadoop provides to combat this  
          Speculative Execution 

          Q18. How does speculative execution works in Hadoop 
          Job tracker makes different task trackers process same input. When tasks complete, they announce this fact to the Job Tracker. Whichever copy of a task finishes first becomes the definitive copy. If other copies were executing speculatively, Hadoop tells the Task Trackers to abandon the tasks and discard their outputs. The Reducers then receive their inputs from whichever Mapper completed successfully, first. 

          Q19. Using command line in Linux, how will you 
          - see all jobs running in the hadoop cluster
          - kill a job
          hadoop job -list
          hadoop job -kill jobid 

          Q20. What is Hadoop Streaming 
          Streaming is a generic API that allows programs written in virtually any language to be used asHadoop Mapper and Reducer implementations 


          Q21. What is the characteristic of streaming API that makes it flexible run map reduce jobs in languages like perl, ruby, awk etc. 
          Hadoop Streaming allows to use arbitrary programs for the Mapper and Reducer phases of a Map Reduce job by having both Mappers and Reducers receive their input on stdin and emit output (key, value) pairs on stdout.
          Q22. Whats is Distributed Cache in Hadoop
          Distributed Cache is a facility provided by the Map/Reduce framework to cache files (text, archives, jars and so on) needed by applications during execution of the job. The framework will copy the necessary files to the slave node before any tasks for the job are executed on that node.
          Q23. What is the benifit of Distributed cache, why can we just have the file in HDFS and have the application read it 
          This is because distributed cache is much faster. It copies the file to all trackers at the start of the job. Now if the task tracker runs 10 or 100 mappers or reducer, it will use the same copy of distributed cache. On the other hand, if you put code in file to read it from HDFS in the MR job then every mapper will try to access it from HDFS hence if a task tracker run 100 map jobs then it will try to read this file 100 times from HDFS. Also HDFS is not very efficient when used like this.

          Q.24 What mechanism does Hadoop framework provides to synchronize changes made in Distribution Cache during runtime of the application 
          This is a trick questions. There is no such mechanism. Distributed Cache by design is read only during the time of Job execution

          Q25. Have you ever used Counters in Hadoop. Give us an example scenario
          Anybody who claims to have worked on a Hadoop project is expected to use counters

          Q26. Is it possible to provide multiple input to Hadoop? If yes then how can you give multiple directories as input to the Hadoop job 
          Yes, The input format class provides methods to add multiple directories as input to a Hadoop job

          Q27. Is it possible to have Hadoop job output in multiple directories. If yes then how 
          Yes, by using Multiple Outputs class

          Q28. What will a hadoop job do if you try to run it with an output directory that is already present? Will it
          - overwrite it
          - warn you and continue
          - throw an exception and exit

          The hadoop job will throw an exception and exit.

          Q29. How can you set an arbitary number of mappers to be created for a job in Hadoop 
          This is a trick question. You cannot set it

          Q30. How can you set an arbitary number of reducers to be created for a job in Hadoop 
          You can either do it progamatically by using method setNumReduceTasksin the JobConfclass or set it up as a configuration setting

           

          Src:http://xsh8637.blog.163.com/blog/#m=0&t=1&c=fks_084065087084081065083083087095086082081074093080080069

          posted @ 2012-11-09 19:48 abin 閱讀(2354) | 評論 (0)編輯 收藏

          我們經常在linux要查找某個文件,但不知道放在哪里了,可以使用下面的一些命令來搜索。這些是從網上找到的資料,因為有時很長時間不會用到,當要用的時候經常弄混了,所以放到這里方便使用。 
          which       查看可執行文件的位置 
          whereis    查看文件的位置 
          locate       配 合數據庫查看文件位置 
          find          實際搜尋硬盤查詢文件名稱 

          1、which 
          語法: 
          [root@redhat ~]# which 可執行文件名稱 
          例如: 
          [root@redhat ~]# which passwd 
          /usr/bin/passwd 
          which是通過 PATH環境變量到該路徑內查找可執行文件,所以基本的功能是尋找可執行文件 

          2、whereis 
          語法: 
          [root@redhat ~]# whereis [-bmsu] 文件或者目錄名稱 
          參數說 明: 
          -b : 只找二進制文件 
          -m: 只找在說明文件manual路徑下的文件 
          -s : 只找source源文件 
          -u : 沒有說明文檔的文件 
          例如: 
          [root@redhat ~]# whereis passwd 
          passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz 
          將和passwd文件相關的文件都查找出來 

          [root@redhat ~]# whereis -b passwd 
          passwd: /usr/bin/passwd /etc/passwd 
          只將二進制文件 查找出來 

          和find相比,whereis查找的速度非常快,這是因為linux系統會將 系統內的所有文件都記錄在一個數據庫文件中,當使用whereis和下面即將介紹的locate時,會從數據庫中查找數據,而不是像find命令那樣,通 過遍歷硬盤來查找,效率自然會很高。 
          但是該數據庫文件并不是實時更新,默認情況下時一星期更新一次,因此,我們在用whereis和locate 查找文件時,有時會找到已經被刪除的數據,或者剛剛建立文件,卻無法查找到,原因就是因為數據庫文件沒有被更新。 

          3、 locate 
          語法: 
          [root@redhat ~]# locate 文件或者目錄名稱 
          例 如: 
          [root@redhat ~]# locate passwd 
          /home/weblogic/bea/user_projects/domains/zhanggongzhe112/myserver/stage/_appsdir_DB_war/DB.war/jsp/as/user/passwd.jsp
          /home/weblogic/bea/user_projects/domains/zhanggongzhe112/myserver/stage/_appsdir_admin_war/admin.war/jsp/platform/passwd.jsp
          /lib/security/pam_unix_passwd.so 
          /lib/security/pam_passwdqc.so 
          /usr/include/rpcsvc/yppasswd.x 
          /usr/include/rpcsvc/yppasswd.h 
          /usr/lib/perl5/5.8.5/i386-linux-thread-multi/rpcsvc/yppasswd.ph 
          /usr/lib/kde3/kded_kpasswdserver.la 
          /usr/lib/kde3/kded_kpasswdserver.so 
          /usr/lib/ruby/1.8/webrick/httpauth/htpasswd.rb 
          /usr/bin/vncpasswd 
          /usr/bin/userpasswd 
          /usr/bin/yppasswd 
          ………… 

          4、 find 
          語法: 
          [root@redhat ~]# find 路徑 參數 
          參 數說明: 
          時間查找參數: 
          -atime n :將n*24小時內存取過的的文件列出來 
          -ctime n :將n*24小時內改變、新增的文件或者目錄列出來 
          -mtime n :將n*24小時內修改過的文件或者目錄列出來 
          -newer file :把比file還要新的文件列出來 
          名稱查找參數: 
          -gid n       :尋找群組ID為n的文件 
          -group name  :尋找群組名稱為name的文件 
          -uid n       :尋找擁有者ID為n的文件 
          -user name   :尋找用戶者名稱為name的文件 
          -name file   :尋找文件名為file的文件(可以使用通配符) 
          例 如: 
          [root@redhat ~]# find / -name zgz 
          /home/zgz 
          /home/zgz/zgz 
          /home/weblogic/bea/user_projects/domains/zgz 
          /home/oracle/product/10g/cfgtoollogs/dbca/zgz 
          /home/oracle/product/10g/cfgtoollogs/emca/zgz 
          /home/oracle/oradata/zgz 

          [root@redhat ~]# find / -name '*zgz*' 
          /home/zgz 
          /home/zgz/zgz1 
          /home/zgz/zgzdirzgz 
          /home/zgz/zgz 
          /home/zgz/zgzdir 
          /home/weblogic/bea/user_projects/domains/zgz 
          /home/weblogic/bea/user_projects/domains/zgz/zgz.log00006 
          /home/weblogic/bea/user_projects/domains/zgz/zgz.log00002 
          /home/weblogic/bea/user_projects/domains/zgz/zgz.log00004 
          /home/weblogic/bea/user_projects/domains/zgz/zgz.log 
          /home/weblogic/bea/user_projects/domains/zgz/zgz.log00008 
          /home/weblogic/bea/user_projects/domains/zgz/zgz.log00005 

          當我們用whereis和locate無法查找到我們需要的文件時,可以使用find,但是find是在硬盤上遍歷查 找,因此非常消耗硬盤的資源,而且效率也非常低,因此建議大家優先使用whereis和locate。 
          locate 是在數據庫里查找,數據庫大至每天更新一次。 
          whereis 可以找到可執行命令和man page 
          find 就是根據條件查找文件。 
          which 可以找到可執行文件和別名(alias)
          posted @ 2012-11-09 16:19 abin 閱讀(378) | 評論 (0)編輯 收藏

          nmap 使用介紹

          nmap是目前為止最廣為使用的國外端口掃描工具之一。我們可以從http://www.insecure.org/進 行下載,可以很容易的安裝到Windows和unix操作系統中,包括mac os x(通過configure、make 、make install等命令)也可以直接從http://www.insecure.org/下載windows二進制(包括所需要的winpcap)也可以從 http://www.nmapwin.org/獲得nmap的圖形windows。

          掃描主機

          $ nmap -sT 192.168.1.18 
          Starting nmap 3.48(http://www.insecure.org/nmap/)at 2007-10-10 18:13
          EDT Interesting ports on gamebase(192.168.1.18)
           port state serverice
          22/tcp open ssh
          111/tcp open sunrpc
          ..........
          $ nmap -sR 192.168.1.18
          Startingnmap 3.48(http://www.insecure.org/nmap/)at 2007-10-10 18:13
          EDT Interesting ports on gamebase(192.168.1.18)
          port state serverice
          22/tcp open ssh
          111/tcp open sunrpc
          ..........

          我們可以使用ping掃描的方法(-sP),與fping的工作方式比較相似,它發送icmp回送請求到指定范圍的ip地址并等待響應。現在很多主 機在掃描的時候都做了處理,阻塞icmp請求,這種情況下。nmap將嘗試與主機的端口80進行連接,如果可以接收到響應(可以是syn/ack,也可以 是rst),那么證明主機正在運行,反之,則無法判斷主機是否開機或者是否在網絡上互連。

          掃描tcp端口

          這里-sR是怎樣在打開的端口上利用RPC命令來判斷它們是否運行了RPC服務。

          nmap可以在進行端口掃描的tcp報文來做一些秘密的事情。首先,要有一個SYN掃描(-sS),它只做建立TCP連接的前面一些工作,只發送一 個設置SYN標志的TCP報文,一個RESET報文,那么nmap假設這個端口是關閉的,那么就不做任何事情了。如果接收到一個響應,它并不象正常的連接 一樣對這個報文進行確認,而是發送一個RET報文,TCP的三次握手還沒有完成,許多服務將不會記錄這次連接。

          有的時候,nmap會告訴我們端口被過濾,這意味著有防火墻或端口過濾器干擾了nmap,使其不能準確的判斷端口是打開還是關閉的,有的防火墻只能過濾掉進入的連接。

          掃描協議

          如果試圖訪問另一端無程序使用的UDP端口,主機將發回一個icmp“端口不可達”的提示消息,IP協議也是一樣。每個傳輸層的IP協議都有一個相 關聯的編號,使用最多的是ICMP(1)、TCP(6)和UDP(17)。所有的IP報文都有一個“協議”域用于指出其中的傳輸層報文頭所使用的協議。如 果我們發送一個沒有傳輸層報文頭的原始IP報文并把其協議域編號為130[該編號是指類似IPSEC協議的被稱為安全報文外殼或SPS協議],就可以判斷 這個協議是否在主機上實現了。如果我們得到的是ICMP協議不可達的消息,意味著該協議沒有被實現,否則就是已經實現了,用法為-sO.

          隱蔽掃描行為

          nmap給出了幾個不同的掃描選項,其中一些可以配套著隱藏掃描行為,使得不被系統日志、防火墻和IDS檢測到。提供了一些隨機的和欺騙的特性。具體例子如下:

          FTP反彈,在設計上,FTP自身存在一個很大的漏洞,當使用FTP客戶機連接到FTP服務器時,你的客戶機在TCP端口21上與FTP服務器對 話,這個TCP連接稱為控制連接。FTP服務器現在需要另一條與客戶機連接,該連接稱為數據連接,在這條連接上將傳送實際的文件數據,客戶機將開始監聽另 一個TCP端口上從服務器發揮的數據連接,接下來執行一個PORT命令到服務器,告訴它建立一條數據連接到客戶機的IP地址和一個新打開的端口,這種操作 方法稱為主動傳輸。許多客戶機使用網絡地址轉換或通過防火墻與外界連接,所以主動傳輸FTP就不能正常工作,因為由服務器建立的客戶機的連接通常不允許通 過。

          被動傳輸是大多數FTP客戶機和服務器所使用的方法,因為客戶機既建立控制連接又建立數據連接,這樣可以通過防火墻或NAT了。

          FTP的PORT命令,用來告訴FTP連接的服務器,使得與剛剛打開的用于數據連接的端口之間建立一個連接。由于我們不僅指定端口而且指定連接所用 的IP地址,所以客戶端也可以通過PORT命令讓服務器連接到任何地方。所以我們一樣可以讓nmap用這個方法進行防火墻穿透。nmap做的所有工作是與 一臺服務器建立一個主動模式的FTP連接,并發送一個包含它試圖掃描的主機IP地址和端口號的PORT命令。

          nmap -b aaa@ftp.target.com -p 6000 192.168.1.226
          nmap 與ftp服務器的對話的例子:
          server:220  target ftp server version 4 ready
          client:user  anonymous
          server: 331 Guest login ok ,send e-mail as password
          client:pass
          server :230 login successful
          client:PORT 192,168,1.226,23,112
          server:200 PORT command successful
          client:LIST
          server:150 Opening ASCII connection for '/bin/ls'
          server:226 Transfer complete

          PORT命令起作用,可以制造是別人進行端口掃描,掃描任何FTP服務器所能訪問的主機,繞過防火墻和端口過濾器,但還是存在一些危險的,如果對方登陸到了你的這個匿名FTP服務器上,從日志查找到相應的匿名FTP連接,從而知道你的IP地址,這樣就直接暴露了。

          nmap -sI 空閑掃描,主要是欺騙端口掃描的源地址。

          nmap -f 可以把TCP頭分片的IP報文進行一些隱蔽的掃描。不完整的TCP報文不被防火墻阻塞也不被IDS檢測到。

          nmap-D
          選擇幾臺肉雞,并使用-D標志在命令行中指定它們。namp通過誘騙的IP地址來進行欺騙式端口掃描,而系統管理員可以同時看到不同的端口掃描,而只有一個是真實的,很好的保護了自己。

          os指紋識別
          這個是nmap最有用的功能之一,就是可以鑒別遠程主機。通過簡單的執行網絡掃 描,nmap通常可以告訴你遠程主機所運行的OS,甚至詳細到版本號。當你指定-Q標志時,nmap將用幾種不同的技術從主機返回IP報文中尋找這些鑒別 信息。通過發送特別設計的TCP和UDP頭,nmap可以得到遠程主機對TCP/IP協議棧的處理方法。它將分析結果與保存在文件中的已知特征信息進行比 較。

          OS鑒別選項也可以讓nmap對TCP報文進行分析以決定另外一些信息,如系統的啟動時間,TCP序列號,預測的序列號使我們更容易截獲報文并猜測序列號從而偽造TCP連接。

          nmap命令使用詳細解釋

          -P0 -PT -PS -PU -PE -PP -PM -PB 當nmap進行某種類型的端口或協議掃描時,通常都會嘗試先ping 主機,這種嘗試可使nmap不會浪費時間在那些未開機的主機上,但是許多主機與防火墻會阻塞ICMP報文,我們希望能通過控制使用。

          -P0  告訴nmap不ping 主機,只進行掃描

          -PT  告訴nmap使用TCP的ping

          -PS  發送SYN報文。

          -PU  發送一個udp ping

          -PE  強制執行直接的ICMP ping

          -PB  這是默認類型,可以使用ICMP ping 也可以使用TCP ping .

          -6   該標志允許IPv6支持

          -v  -d  使用-v選項可得到更詳細的輸出,而-d選項則增加調試輸出。

          -oN  按照人們閱讀的格式記錄屏幕上的輸出,如果是在掃描多臺機器,則該選項很有用。

          -oX  以xml格式向指定的文件記錄信息

          -oG  以一種易于檢索的格式記錄信息,即每臺主機都以單獨的行來記錄所有的端口和0s信息。

          -oA  使用為基本文件名,以普通格式(-oN)、XML格式(-oX)和易于檢索的格式(-oG)jilu  xinxi 

          -oM  把輸出格式化為機器可閱讀的文件

          -oS  把輸出進行傻瓜型排版

          --resume如果你取消了掃描,但生成了供人或者供機器閱讀的文件,那么可以把該文件提供給nmap繼續讓它掃描。

          -iR-iL可以不在命令行中指定目標主機,而是使用-iR選項隨即產生待掃描的主機,或者使用-iL選項從一個包含主機名或IP地址列表的文件中讀取目標主機,這些主機名或IP地址使用空格、制表符或換行隔開。

          -F nmap只掃描在nmap內建的服務文件中已知的端口,如果不指定該選項,nmap將掃描端口 1-1024及包含在nmap-services文件中的所有其他端口。如果用-sO選項掃描協議,nmap將用它內建的協議文件(nmap- protocols文件)而不是默認地掃描所有256個協議。

          -A nmap使用所有的高級掃描選項

          -p 參數可以是一個單獨的端口、一個用逗號隔開的端口列表、一個使用“-”表示的端口范圍或者上述格式的任意組合。如果沒有指定該選項,nmap將對包含前1024個端口的所有端口進行一次快速掃描。

          -e在多穴主機中,可以指定你用來進行網絡通信的網絡接口。

          -g可以選擇一個源端口,從該端口執行所有的掃描。

          --ttlnmap其發送的任何報文在到中間路由器的跳后會失效。

          --packet-trace 可以顯示掃描期間nmap發送和接收的各個報文的詳細列表,這對調試非常有用。要與-o選項之一聯合使用,需要根權限,以將所有的數據記錄到文件。

          --scanflags可以使用這個選項手工的指定欲在掃描報文中設置的TCP標志。也可以指定TCP標志的OOred值的整數形式,或者標志的字符串表示形式。

          以上介紹的就是nmap在windows下和unix中的命令介紹。


          posted @ 2012-11-09 13:11 abin 閱讀(1840) | 評論 (0)編輯 收藏

          在主界面Filter欄里輸入ip.addr==192.168.1.98&&http就可以了,合法的過濾條件的底色為淺綠色。Capture filter和display filter語法不同,后者的大多數表達法都不:適用于前者。另外,ip.src僅過濾源地址為指定地址的數據包,ip.dst僅過濾目的地址為指定地址的數據包,ip.addr或許才是你需要的。
          posted @ 2012-11-09 12:43 abin 閱讀(621) | 評論 (0)編輯 收藏

          如果你是一位網絡應用開發者,你在開發過程中肯定會使用到網絡協議分析器(network protocol analyzer), 我們也可以稱之為“嗅探器”。eEye 公司有一款很不錯的網絡協議分析器產品 “Iris”, 我一直使用它的 4.07 版本,由于其功能完備,一直沒有太多的關注其他同類軟件,但此版本不能工作在 Windows Vista 上,也不能對無線網絡適配器進行分析,而我恰好要在 Vista 上做很多開發工作,又經常使用無線網絡連接的筆記本電腦,Iris 4.07 無法滿足我的工作需求了。

          幸運的是,Wireshark(線鯊)一款基于 winpcap/tcpdump 的開源網絡協議分析軟件對vista和無線網絡的兼容都很好。他的前身就是Ethereal。他具備了和 Iris 同樣強大的 Decode 能力,甚至線性截包的能力超過 iris。要用好分析器很重要的一點就是設置好 Filter(過濾器),在這一點上 Wireshark 的過濾表達式更顯強大。

          我們來看個幾個簡單的過濾器例子:

          “ip.dst==211.244.254.1” (所有目標地址是211.244.254.1的ip包)

          “tcp.port==80″ (所有tcp端口是80的包)

          你可以把上述表達式用 and 連接起來

          “(ip.dst==211.244.254.1) and (tcp.port==80)”

          或者再稍加變換

          “(ip.dst==211.244.254.1) and !(tcp.port==80)” (所有目的ip是211.244.254.1非 80 端口)

          使用表達式設置過濾器比之在界面上選擇/填空更加快捷靈活,如果你不熟悉這些表達式,Wireshark 也提供了設置界面,并且最終生成表達式,這樣也方便了使用者學習。

          Wireshark 還提供了更高級的表達式特性,請看如下表達式

          (tcp.port==80) and (ip.dst==211.244.254.1) and (http[5:2]==7075)

          對象 http 就是 wireshark 解碼以后的 http 數據部分 http[5:2] 就是指從 下標 5 開始的兩個字節,請思考一下這樣的http 請求

          GET /pu*****

          怎么樣,如果你在瀏覽器中訪問 http://www.google.com/pu 或者 http://www.google.com/put 或者 http://www.google.com/pub 都會被記錄下來,匹配 *****pu***… 了

          這樣我們就可以方便的將我們需要檢測的某個特別的網絡指令過濾出來。

          比如我在幫某硬件編寫上位機程序的時候,指令總是以固定格式發送的,很容易我們就能過濾掉煩人的無用的信息,大大的提升了工作效率。

          轉自cp62的專欄,http://blog.csdn.net/cp62/archive/2008/12/25/3603372.aspx

          posted @ 2012-11-09 12:41 abin 閱讀(2157) | 評論 (0)編輯 收藏

          package com.abin.lee.servlet.mythread.runnable;

          import java.util.concurrent.atomic.AtomicInteger;

          public class SumThread implements Runnable{
           private  AtomicInteger num=new AtomicInteger(0);
           public void run(){
            while(num.get()<100){
             try {
              Thread.sleep(100);
             } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
             }
             if(num.get()==40){
              Thread thread2=new Thread(this,"thread2");
              thread2.start();
             }
             System.out.println(Thread.currentThread().getName()+":"+num.getAndIncrement());
            }
           }
           
          }












          package com.abin.lee.servlet.mythread.runnable;

          public class SumThreadTest {
           public static void main(String[] args) {
            SumThread ru=new SumThread();
            Thread thread1=new Thread(ru,"thread1");
            thread1.start();
           }
          }

          posted @ 2012-11-05 22:40 abin 閱讀(1572) | 評論 (0)編輯 收藏

          僅列出標題
          共50頁: First 上一頁 22 23 24 25 26 27 28 29 30 下一頁 Last 
          主站蜘蛛池模板: 伽师县| 乌拉特后旗| 德化县| 萨迦县| 同心县| 菏泽市| 彝良县| 响水县| 阿克| 东光县| 于都县| 五莲县| 湛江市| 梓潼县| 湖北省| 东兰县| 青阳县| 冕宁县| 佛冈县| 花垣县| 乌拉特中旗| 景洪市| 荆门市| 于田县| 万州区| 宝清县| 区。| 鄢陵县| 灵石县| 屏山县| 兴国县| 黄平县| 七台河市| 陆丰市| 桓仁| 晋城| 姜堰市| 微山县| 赣榆县| 肇州县| 南宫市|