




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、計算機網(wǎng)絡(luò)課程設(shè)計 論文題目: 簡單端口掃描程序的實現(xiàn) 院(部)名 稱: 計算機科學與工程學院 學 生 姓 名: 專 業(yè): 學 號: 指導教師姓名: 報告提交時間: 報告答辯時間: (不填) 目錄一、設(shè)計要求2二、開發(fā)環(huán)境與工具2三、設(shè)計原理2四、系統(tǒng)功能描述及軟件模塊劃分2五、設(shè)計步驟2六、關(guān)鍵問題及其解決方法2七、設(shè)計結(jié)果3八、軟件使用說明3九、參考資料3 一、設(shè)計要求本系統(tǒng)實現(xiàn)了一個簡單的端口掃描器。1. 使用端口掃描對一臺主機進行掃描,一臺主機上有哪些端口是打開的;2. 對一個網(wǎng)段進行 IP 掃描,顯示出一個網(wǎng)段內(nèi)有哪些主機是開機的。二、開發(fā)環(huán)境與工具Windows的pc機Jdk包,:
2、具備網(wǎng)絡(luò)環(huán)境并連入Internet。三、設(shè)計原理IP地址和端口被稱作套接字,它代表一個TCP連接的一個連接端。為了獲得TCP服務(wù),必須在發(fā)送機的一個端口上和接收機的一個端口上建立連接。TCP連接用兩個連接端來區(qū)別,也就是(連接端1,連接端2)。連接端互相發(fā)送數(shù)據(jù)包。端口掃描是在應(yīng)用程序運行在 TCP 或者 UDP 協(xié)議之上工作的, 這些協(xié)議是眾多應(yīng)用程序使用的傳輸機制,端口掃描是通過掃描主機確定哪一些 TCP 和 UDP 端口可以訪問的過程. 端口掃描常見的幾種類型: TCP Connect()掃描 SYN 掃描 NULL 掃描 ACK 掃描 Xmas-Tree Dumb 掃描。 Ping命令
3、經(jīng)常用來對TCP/IP網(wǎng)絡(luò)進行診斷。通過目標計算機發(fā)送一個數(shù)據(jù)包,讓它將這個數(shù)據(jù)包反送回來,如果返回的數(shù)據(jù)包和發(fā)送的數(shù)據(jù)包一致,那就是說你的PING命令成功了。通過這樣對返回的數(shù)據(jù)進行分析,就能判斷計算機是否開著,或者這個數(shù)據(jù)包從發(fā)送到返回需要多少時間。 Tracert命令用來跟蹤一個消息從一臺計算機到另一臺計算機所走的路徑, rusers和finger 通過這兩個命令,你能收集到目標計算機上的有關(guān)用戶的消息。 掃描器通過選用遠程TCP/IP不同的端口的服務(wù),并記錄目標給予的回答,通過這種方法,可以搜集到很多關(guān)于目標主機的各種有用的信息??傊?,端口掃描”通常指用同一信息對目標計算機的所有所需掃
4、描的端口進行發(fā)送,然后根據(jù)返回端口狀態(tài)來分析目標計算機的端口是否打開、是否可用?!岸丝趻呙琛毙袨榈囊粋€重要特征,是在短時期內(nèi)有很多來自相同的信源地址,傳向不同的目的、地端口的包。對于用端口掃描進行攻擊的人來說,攻擊者總是可以做到在獲得掃描結(jié)果的同時,使自己很難被發(fā)現(xiàn)或者說很難被逆向?qū)ほ?。為了隱藏攻擊,攻擊者可以慢慢地進行掃描。除非目標系統(tǒng)通常閑著(這樣對一個沒有l(wèi)isten()端口的數(shù)據(jù)包都會引起管理員的注意),有很大時間間隔的端口掃描是很難被識別的。隱藏源地址的方法是發(fā)送大量的欺騙性的端口掃描數(shù)據(jù)包(如1 000個),其中只有一個是從真正的源地址來的。這樣即使全部數(shù)據(jù)包都被察覺,被記錄下來,
5、也沒有人知道哪個是真正的信源地址。能發(fā)現(xiàn)的僅僅是“曾經(jīng)被掃描過”的地址。也正因為這樣,那些黑客們才樂此不疲地繼續(xù)大量使用,這種端口掃描技術(shù),來達到他們獲取目標計算機信息,并進行惡意攻擊的目的。通常進行端口掃描的工具目前主要采用的是端口掃描軟件,也稱之為“端口掃描器”。端口掃描器也是一種程序,它可以對目標主機的端口進行連接,并記錄目標端口的應(yīng)答。端口掃描器通過選用遠程TCP/IP協(xié)議不同的端口的服務(wù),記錄目標計算機端口給予回答的方法,可以收集到很多關(guān)于目標計算機的各種有用信息(比如是否有端口在偵聽,是否允許匿名登錄,是否有可寫的FTP目錄,是否能用Telnet等)。 雖然端口掃描器可以用于正常網(wǎng)
6、絡(luò)安全管理,但就目前來說,它主要還是被黑客所利用,是黑客入侵、攻擊前期不可缺少的工具。黑客一般先使用掃描工具掃描待入侵主機,掌握目標主機的端口打開情況,然后采取相應(yīng)的入侵措施。 無論是正常用途,還是非法用途,端口掃描可以提供4個用途。1.識別目標主機上有哪些端口是開放的,這是端口掃描的最基本目的。2.識別目標系統(tǒng)的操作系統(tǒng)類型(Windows、Linux或UNIX等)。3.識別某個應(yīng)用程序或某個特定服務(wù)的版本號。4.識別目標系統(tǒng)的系統(tǒng)漏洞,這是端口掃描的一種新功能。 當然以上這些功能不可能是一成不變的,隨著技術(shù)的不斷完善,新的功能會不斷地增加。端口掃描器并不是一個直接攻擊網(wǎng)絡(luò)漏洞的程序,它僅僅
7、能幫助發(fā)現(xiàn)目標計算機的某些內(nèi)在的弱點。一個好的掃描器還能對它得到的數(shù)據(jù)進行分析,幫助查找目標計算機的漏洞。但它不會提供一個系統(tǒng)的詳細步驟。編寫掃描器程序必須要很多TCP/IP協(xié)議程序,以及C、Perl和SHELL語言的知識,還需要一些Socket編程的背景。四、系統(tǒng)功能描述及軟件模塊劃分主要功能有:1. 使用端口掃描對一臺主機進行掃描,一臺主機上有哪些端口是打開的;2. 對一個網(wǎng)段進行 IP 掃描,顯示出一個網(wǎng)段內(nèi)有哪些主機是開機的。軟件所包含的主要模塊有:1.對IP的處理。包括對IP的移位和運算等。2.對本機個端口的掃描。3.對本網(wǎng)段的其他主機個端口的掃描。五、設(shè)計步驟六、關(guān)鍵問題及其解決方
8、法 完整的代碼如下: import java.io.*; import .*; import java.util.*; import java.lang.*; import java.lang.String.*; import java.lang.Integer.*; import java.awt.*; public class ScanPort2 public static void main(String args) System.out.println(); System.out.println(" *自定義多IP多TCP端口掃描程序*"); System.out.
9、println(" *按Ctrl+c退出掃描*"); String shubeginip="",shuendip="" String sp1="",sp2="",sp3="" int beginport,endport; int maxThread=0; / 異常判斷變量 int bport=0,eport=0; boolean bool = false; boolean bool1 = false; boolean bool2 = false; boolean bool3
10、= false; boolean bool4 = false; long xxx=0,xxx2=0; /由用戶輸入掃描范圍/讀取輸入開始ip System.out.println(); System.out.println("請輸入起始ip:"); while(!bool) try BufferedReader in1=new BufferedReader(new InputStreamReader(System.in); shubeginip=in1.readLine(); xxx=Com.ipj(shubeginip); if(xxx=0) bool=false; Sy
11、stem.out.println("IP格式錯誤,請輸入正確的起始ip:"); else if(xxx<=Com.ipj("") bool=false; System.out.println("IP范圍錯誤,請輸入正確的起始ip:"); else bool=true; catch(IOException e)System.out.println("IP格式錯誤,請輸入正確的起始ip:"); catch(NumberFormatException e)System.out.println(&quo
12、t;IP格式錯誤,請輸入正確的起始ip:"); catch(StringIndexOutOfBoundsException e)System.out.println("IP格式錯誤,請輸入正確的開始ip:"); catch(NullPointerException e)System.out.print("退出程序!"); /讀取輸入結(jié)束ip System.out.println(); System.out.println("請輸入結(jié)束ip:"); while(!bool1) try BufferedReader in2=ne
13、w BufferedReader(new InputStreamReader(System.in); shuendip=in2.readLine(); xxx2=Com.ipj(shuendip); if(xxx2=0) bool1=false; System.out.println("IP格式錯誤,請輸入正確的結(jié)束ip:"); else if(Math.abs(xxx2-xxx)>5155130) bool1=false; System.out.println("掃描IP數(shù)不能大于5155130,請輸入正確的結(jié)束ip:"); else bool1
14、=true; catch(IOException e)System.out.println("IP格式錯誤,請輸入正確的結(jié)束ip:"); catch(NumberFormatException e)System.out.println("IP格式錯誤,請輸入正確的結(jié)束ip:"); catch(StringIndexOutOfBoundsException e)System.out.println("IP格式錯誤,請輸入正確的結(jié)束ip:"); catch(NullPointerException e)System.out.print(&
15、quot;退出程序!"); /讀取輸入起始端口 System.out.println(); System.out.println("請輸入起始端口:"); while(!bool2) try BufferedReader in3=new BufferedReader(new InputStreamReader(System.in); sp1=in3.readLine(); bport=Integer.parseInt(sp1); if(bport<0|bport>65535) System.out.println("端口錯誤,請輸入正確的起始
16、端口:"); bool2=false; else bool2=true; catch(IOException e)System.out.println("端口錯誤,請輸入正確的起始端口:"); catch(NumberFormatException e)System.out.println("端口錯誤,請輸入正確的起始端口:"); beginport=Integer.parseInt(sp1);/讀取輸入結(jié)束端口 System.out.println(); System.out.println("請輸入結(jié)束端口:"); wh
17、ile(!bool3) try BufferedReader in4=new BufferedReader(new InputStreamReader(System.in); sp2=in4.readLine(); eport=Integer.parseInt(sp2); if(eport<beginport|eport>65535) System.out.println("端口錯誤,請輸入正確的結(jié)束端口:"); bool3=false; else bool3=true; catch(IOException e)System.out.println("
18、端口錯誤,請輸入正確的結(jié)束端口:"); catch(NumberFormatException e)System.out.println("端口錯誤,請輸入正確的起始端口:"); endport=Integer.parseInt(sp2); /讀取輸入最大線程數(shù) System.out.println(); System.out.println("請輸入最大線程(1-300):"); while(!bool4) try BufferedReader in5=new BufferedReader(new InputStreamReader(Syst
19、em.in); sp3=in5.readLine(); maxThread=Integer.parseInt(sp3); if(maxThread>300|maxThread<1) System.out.println("請輸入1-300之間的整數(shù):"); bool4=false; else bool4=true; catch(IOException e)System.out.print("退出程序!"); catch(NumberFormatException e)System.out.println("請輸入1-300之間的整數(shù)
20、"); catch(NullPointerException e)System.out.print("退出程序!"); maxThread=Integer.parseInt(sp3); /開始掃描 System.out.println("正在處理IP地址"); long long_beginip=Com.ipj(shubeginip);/轉(zhuǎn)換ip long long_endip=Com.ipj(shuendip); int allport=endport-beginport+1;/計算掃描端口總數(shù) int allip=(int)Math.abs
21、(long_beginip - long_endip) + 1; int t1=0,t2=0; /計算耗時 long begint,endt,alltime; Date mydate=new Date(); begint=mydate.getTime(); /獲取當前時間 try /計算兩個ip值之間的所有ip long ipduan=new long(int)Math.abs(long_beginip - long_endip) + 1; for(int k=0;k<=Math.abs(long_beginip - long_endip);k+) if (long_beginip-lo
22、ng_endip < 0) ipduank=long_beginip+k; else ipduank=long_endip+k; String ips1=new Stringipduan.length; System.out.println("正在掃描"); for(int a=0;a<=ipduan.length;a+) ips1a=Com.ipk(ipduana); if(ips1a!=null) System.out.println("正在掃描:"+ips1a); for(int xPort=beginport;xPort<=en
23、dport;xPort+ ) int x=quanjubianliang.Threadnum; if(x>maxThread) try Thread.sleep(100); catch(InterruptedException e) String threadName="thread"+xPort; if(xPort!=21) new ScanThread(ips1a,xPort,threadName).start(); else allip=allip-1; catch(Exception exp)System.out.println(); Date mydate2
24、=new Date(); /獲取結(jié)束時間 try Thread.sleep(1000); catch(InterruptedException e) System.out.println("掃描完成!"); endt=mydate2.getTime(); alltime=endt-begint; System.out.print("掃描了"+allip+"個IP共"+allip*allport+"個端口,用時"+alltime+"毫秒"); /全局變量,用做限制最大線程 class quanju
25、bianliang public static int Threadnum=0; /掃描線程 class ScanThread extends Thread private String ghost; private int scanP; public ScanThread(String h,int mPort,String threadName) ghost=h; scanP=mPort; public void run() quanjubianliang.Threadnum=quanjubianliang.Threadnum+1; try SocketAddress sockaddr =
26、new InetSocketAddress(ghost,scanP); Socket scans=new Socket(); int timeoutMs=50; scans.connect(sockaddr, timeoutMs); scans.close(); System.out.println("主機:"+ghost+" TCP端口:"+scanP+" 在線"); catch(SocketTimeoutException e) catch(IOException e) quanjubianliang.Threadnum=quan
27、jubianliang.Threadnum-1; /ip處理 class Com /將字符串ip轉(zhuǎn)換成長整型 public static long ipj(String ipAddress) long ip=new long4; int position1=ipAddress.indexOf("."); int position2=ipAddress.indexOf(".",position1+1); int position3=ipAddress.indexOf(".",position2+1); ip0=Long.parseLong(ipAddress.substring(0,position1); ip1=Long.parseLong(ipAddress.sub
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 賣專利合同范本
- 中介租房傭金合同范例
- 同事之間合作合同范例
- 與安保公司合同范例
- 合伙制度合同范例
- 光伏發(fā)電貸款托管合同范例
- 蘭州店鋪租賃合同范例
- 公司繳納社保合同范例
- 合同范例范例填好
- 農(nóng)村輕鋼別墅安裝合同范例
- 保潔巡查記錄表
- 內(nèi)四科修改版護士績效考核表
- 2023汽車用鋁電線束技術(shù)條件
- 設(shè)計變更工作流程(附設(shè)計變更申請表)
- 婦女保健知識講座
- 執(zhí)行申請書范本電子版
- 小學高年級《紅樓春趣》劇本(寧波實驗學校)
- 安徽省縣域?qū)W前教育普及普惠督導評估指標體系
- 第二章-英國學前教育
- 315國際消費者權(quán)益保護日知識講座課件
- 2023年二手房買賣合同正式版
評論
0/150
提交評論