




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、精選優(yōu)質文檔-傾情為你奉上計算機網(wǎng)絡課程設計 論文題目: 簡單端口掃描程序的實現(xiàn) 院(部)名 稱: 計算機科學與工程學院 學 生 姓 名: 專 業(yè): 學 號: 指導教師姓名: 報告提交時間: 報告答辯時間: (不填) 目錄 一、設計要求本系統(tǒng)實現(xiàn)了一個簡單的端口掃描器。1. 使用端口掃描對一臺主機進行掃描,一臺主機上有哪些端口是打開的;2. 對一個網(wǎng)段進行 IP 掃描,顯示出一個網(wǎng)段內有哪些主機是開機的。二、開發(fā)環(huán)境與工具Windows的pc機Jdk包,:具備網(wǎng)絡環(huán)境并連入Internet。三、設計原理IP地址和端口被稱作套接字,它代表一個TCP連接的一個連接端。為了獲得TCP服務,必須在發(fā)送
2、機的一個端口上和接收機的一個端口上建立連接。TCP連接用兩個連接端來區(qū)別,也就是(連接端1,連接端2)。連接端互相發(fā)送數(shù)據(jù)包。端口掃描是在應用程序運行在 TCP 或者 UDP 協(xié)議之上工作的, 這些協(xié)議是眾多應用程序使用的傳輸機制,端口掃描是通過掃描主機確定哪一些 TCP 和 UDP 端口可以訪問的過程. 端口掃描常見的幾種類型: TCP Connect()掃描 SYN 掃描 NULL 掃描 ACK 掃描 Xmas-Tree Dumb 掃描。 Ping命令經常用來對TCP/IP網(wǎng)絡進行診斷。通過目標計算機發(fā)送一個數(shù)據(jù)包,讓它將這個數(shù)據(jù)包反送回來,如果返回的數(shù)據(jù)包和發(fā)送的數(shù)據(jù)包一致,那就是說你的
3、PING命令成功了。通過這樣對返回的數(shù)據(jù)進行分析,就能判斷計算機是否開著,或者這個數(shù)據(jù)包從發(fā)送到返回需要多少時間。 Tracert命令用來跟蹤一個消息從一臺計算機到另一臺計算機所走的路徑, rusers和finger 通過這兩個命令,你能收集到目標計算機上的有關用戶的消息。 掃描器通過選用遠程TCP/IP不同的端口的服務,并記錄目標給予的回答,通過這種方法,可以搜集到很多關于目標主機的各種有用的信息。總之,端口掃描”通常指用同一信息對目標計算機的所有所需掃描的端口進行發(fā)送,然后根據(jù)返回端口狀態(tài)來分析目標計算機的端口是否打開、是否可用。“端口掃描”行為的一個重要特征,是在短時期內有很多來自相同的
4、信源地址,傳向不同的目的、地端口的包。對于用端口掃描進行攻擊的人來說,攻擊者總是可以做到在獲得掃描結果的同時,使自己很難被發(fā)現(xiàn)或者說很難被逆向尋蹤。為了隱藏攻擊,攻擊者可以慢慢地進行掃描。除非目標系統(tǒng)通常閑著(這樣對一個沒有l(wèi)isten()端口的數(shù)據(jù)包都會引起管理員的注意),有很大時間間隔的端口掃描是很難被識別的。隱藏源地址的方法是發(fā)送大量的欺騙性的端口掃描數(shù)據(jù)包(如1 000個),其中只有一個是從真正的源地址來的。這樣即使全部數(shù)據(jù)包都被察覺,被記錄下來,也沒有人知道哪個是真正的信源地址。能發(fā)現(xiàn)的僅僅是“曾經被掃描過”的地址。也正因為這樣,那些黑客們才樂此不疲地繼續(xù)大量使用,這種端口掃描技術,
5、來達到他們獲取目標計算機信息,并進行惡意攻擊的目的。通常進行端口掃描的工具目前主要采用的是端口掃描軟件,也稱之為“端口掃描器”。端口掃描器也是一種程序,它可以對目標主機的端口進行連接,并記錄目標端口的應答。端口掃描器通過選用遠程TCP/IP協(xié)議不同的端口的服務,記錄目標計算機端口給予回答的方法,可以收集到很多關于目標計算機的各種有用信息(比如是否有端口在偵聽,是否允許匿名登錄,是否有可寫的FTP目錄,是否能用Telnet等)。 雖然端口掃描器可以用于正常網(wǎng)絡安全管理,但就目前來說,它主要還是被黑客所利用,是黑客入侵、攻擊前期不可缺少的工具。黑客一般先使用掃描工具掃描待入侵主機,掌握目標主機的端
6、口打開情況,然后采取相應的入侵措施。 無論是正常用途,還是非法用途,端口掃描可以提供4個用途。1.識別目標主機上有哪些端口是開放的,這是端口掃描的最基本目的。2.識別目標系統(tǒng)的操作系統(tǒng)類型(Windows、Linux或UNIX等)。3.識別某個應用程序或某個特定服務的版本號。4.識別目標系統(tǒng)的系統(tǒng)漏洞,這是端口掃描的一種新功能。 當然以上這些功能不可能是一成不變的,隨著技術的不斷完善,新的功能會不斷地增加。端口掃描器并不是一個直接攻擊網(wǎng)絡漏洞的程序,它僅僅能幫助發(fā)現(xiàn)目標計算機的某些內在的弱點。一個好的掃描器還能對它得到的數(shù)據(jù)進行分析,幫助查找目標計算機的漏洞。但它不會提供一個系統(tǒng)的詳細步驟。編
7、寫掃描器程序必須要很多TCP/IP協(xié)議程序,以及C、Perl和SHELL語言的知識,還需要一些Socket編程的背景。四、系統(tǒng)功能描述及軟件模塊劃分主要功能有:1. 使用端口掃描對一臺主機進行掃描,一臺主機上有哪些端口是打開的;2. 對一個網(wǎng)段進行 IP 掃描,顯示出一個網(wǎng)段內有哪些主機是開機的。軟件所包含的主要模塊有:1.對IP的處理。包括對IP的移位和運算等。2.對本機個端口的掃描。3.對本網(wǎng)段的其他主機個端口的掃描。五、設計步驟六、關鍵問題及其解決方法 完整的代碼如下: import java.io.*; import .*; import java.util.*; import jav
8、a.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.println(" *按Ctrl+c退出掃描*"); String shubeginip="",sh
9、uendip="" 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 = false; boolean bool4 = false; long xxx=0,xxx2=0; /由用戶輸入掃描范圍/讀取輸入開始ip
10、 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; System.out.println("IP格式錯誤,請輸入正確的起始ip:"); else if(xxx<=Com.
11、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("IP格式錯誤,請輸入正確的起始ip:"); catch(StringIndexOutOfBoundsException e)S
12、ystem.out.println("IP格式錯誤,請輸入正確的開始ip:"); catch(NullPointerException e)System.out.print("退出程序!"); /讀取輸入結束ip System.out.println(); System.out.println("請輸入結束ip:"); while(!bool1) try BufferedReader in2=new BufferedReader(new InputStreamReader(System.in); shuendip=in2.readLi
13、ne(); xxx2=Com.ipj(shuendip); if(xxx2=0) bool1=false; System.out.println("IP格式錯誤,請輸入正確的結束ip:"); else if(Math.abs(xxx2-xxx)>) bool1=false; System.out.println("掃描IP數(shù)不能大于,請輸入正確的結束ip:"); else bool1=true; catch(IOException e)System.out.println("IP格式錯誤,請輸入正確的結束ip:"); catch
14、(NumberFormatException e)System.out.println("IP格式錯誤,請輸入正確的結束ip:"); catch(StringIndexOutOfBoundsException e)System.out.println("IP格式錯誤,請輸入正確的結束ip:"); catch(NullPointerException e)System.out.print("退出程序!"); /讀取輸入起始端口 System.out.println(); System.out.println("請輸入起始端口:
15、"); 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("端口錯誤,請輸入正確的起始端口:"); bool2=false; else bool2=true; catch(IOException e)System.out.println(&qu
16、ot;端口錯誤,請輸入正確的起始端口:"); catch(NumberFormatException e)System.out.println("端口錯誤,請輸入正確的起始端口:"); beginport=Integer.parseInt(sp1);/讀取輸入結束端口 System.out.println(); System.out.println("請輸入結束端口:"); while(!bool3) try BufferedReader in4=new BufferedReader(new InputStreamReader(System.i
17、n); sp2=in4.readLine(); eport=Integer.parseInt(sp2); if(eport<beginport|eport>65535) System.out.println("端口錯誤,請輸入正確的結束端口:"); bool3=false; else bool3=true; catch(IOException e)System.out.println("端口錯誤,請輸入正確的結束端口:"); catch(NumberFormatException e)System.out.println("端口錯誤
18、,請輸入正確的起始端口:"); endport=Integer.parseInt(sp2); /讀取輸入最大線程數(shù) System.out.println(); System.out.println("請輸入最大線程(1-300):"); while(!bool4) try BufferedReader in5=new BufferedReader(new InputStreamReader(System.in); sp3=in5.readLine(); maxThread=Integer.parseInt(sp3); if(maxThread>300|max
19、Thread<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ù)"); catch(NullPointerException e)System.out.print("退出程序!"); maxThread
20、=Integer.parseInt(sp3); /開始掃描 System.out.println("正在處理IP地址"); long long_beginip=Com.ipj(shubeginip);/轉換ip long long_endip=Com.ipj(shuendip); int allport=endport-beginport+1;/計算掃描端口總數(shù) int allip=(int)Math.abs(long_beginip - long_endip) + 1; int t1=0,t2=0; /計算耗時 long begint,endt,alltime; Date
21、 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-long_endip < 0) ipduank=long_beginip+k; else ipduank=long_endip+k; String ips1=new
22、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<=endport;xPort+ ) int x=quanjubianliang.Threadnum; if(x>maxThread) try Thread.sleep(
23、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=new Date(); /獲取結束時間 try Thread.sleep(1000); catch(InterruptedException e) System.ou
24、t.println("掃描完成!"); endt=mydate2.getTime(); alltime=endt-begint; System.out.print("掃描了"+allip+"個IP共"+allip*allport+"個端口,用時"+alltime+"毫秒"); /全局變量,用做限制最大線程 class quanjubianliang public static int Threadnum=0; /掃描線程 class ScanThread extends Thread priva
25、te 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 = new InetSocketAddress(ghost,scanP); Socket scans=new Socket(); int timeoutMs=50; sca
26、ns.connect(sockaddr, timeoutMs); scans.close(); System.out.println("主機:"+ghost+" TCP端口:"+scanP+" 在線"); catch(SocketTimeoutException e) catch(IOException e) quanjubianliang.Threadnum=quanjubianliang.Threadnum-1; /ip處理 class Com /將字符串ip轉換成長整型 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.substring(pos
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 體育運動訓練指導在線平臺行業(yè)深度調研及發(fā)展項目商業(yè)計劃書
- 美發(fā)沙龍預約與管理APP企業(yè)制定與實施新質生產力項目商業(yè)計劃書
- DB1301T 401-2021 家具末端配送服務規(guī)范
- 單位換算小數(shù)題目及答案
- 2025年動漫IP產業(yè)鏈構建與動漫產業(yè)市場細分領域發(fā)展趨勢研究報告
- 全國交安三類人員考試試題及答案
- 【鄂爾多斯】2025年內蒙古鄂爾多斯市杭錦旗事業(yè)單位校園專場引進急需緊缺專業(yè)人員6人筆試歷年典型考題及考點剖析附帶答案詳解
- 【湖州】2025年上半年浙江湖州市南潯區(qū)事業(yè)單位公開招聘工作人員18人筆試歷年典型考題及考點剖析附帶答案詳解
- 【成都】2025年四川成都市蒲江縣“蓉漂人才薈”公開招聘高層次人才7人筆試歷年典型考題及考點剖析附帶答案詳解
- 【安慶】2025年安慶宿松縣部分事業(yè)單位公開招聘工作人員67人筆試歷年典型考題及考點剖析附帶答案詳解
- 神經性耳鳴護理查房
- 2024年官方獸醫(yī)牧運通考試題庫(含答案)
- 麻醉恢復室病人的護理
- 河砂、碎石生產質量保證措施方案
- 四川燃氣用戶安裝檢修工理論考試題及答案
- 河北省唐山市2025屆高考物理二模試卷含解析
- 2024低壓電力線高速載波通信互聯(lián)互通技術規(guī)范第1部分:總則
- 抖音直播帶貨協(xié)議書模板
- 陳述句與反問句互改(課件)-2022-2023學年三年級語文公開課
- 2025屆浙江省鎮(zhèn)海市鎮(zhèn)海中學高考歷史四模試卷含解析
- 轉租授權委托書及注意事項
評論
0/150
提交評論