




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì) 論文題目: 簡單端口掃描程序的實(shí)現(xiàn) 院(部)名 稱: 計(jì)算機(jī)科學(xué)與工程學(xué)院 學(xué) 生 姓 名: 專 業(yè): 學(xué) 號: 指導(dǎo)教師姓名: 報(bào)告提交時間: 報(bào)告答辯時間: (不填) 目錄 一、設(shè)計(jì)要求本系統(tǒng)實(shí)現(xiàn)了一個簡單的端口掃描器。1. 使用端口掃描對一臺主機(jī)進(jìn)行掃描,一臺主機(jī)上有哪些端口是打開的;2. 對一個網(wǎng)段進(jìn)行 IP 掃描,顯示出一個網(wǎng)段內(nèi)有哪些主機(jī)是開機(jī)的。二、開發(fā)環(huán)境與工具Windows的pc機(jī)Jdk包,:具備網(wǎng)絡(luò)環(huán)境并連入Internet。三、設(shè)計(jì)原理IP地址和端口被稱作套接字,它代表一個TCP連接的一個連接端。為了獲得TCP服務(wù),必須在發(fā)送
2、機(jī)的一個端口上和接收機(jī)的一個端口上建立連接。TCP連接用兩個連接端來區(qū)別,也就是(連接端1,連接端2)。連接端互相發(fā)送數(shù)據(jù)包。端口掃描是在應(yīng)用程序運(yùn)行在 TCP 或者 UDP 協(xié)議之上工作的, 這些協(xié)議是眾多應(yīng)用程序使用的傳輸機(jī)制,端口掃描是通過掃描主機(jī)確定哪一些 TCP 和 UDP 端口可以訪問的過程. 端口掃描常見的幾種類型: TCP Connect()掃描 SYN 掃描 NULL 掃描 ACK 掃描 Xmas-Tree Dumb 掃描。 Ping命令經(jīng)常用來對TCP/IP網(wǎng)絡(luò)進(jìn)行診斷。通過目標(biāo)計(jì)算機(jī)發(fā)送一個數(shù)據(jù)包,讓它將這個數(shù)據(jù)包反送回來,如果返回的數(shù)據(jù)包和發(fā)送的數(shù)據(jù)包一致,那就是說你的
3、PING命令成功了。通過這樣對返回的數(shù)據(jù)進(jìn)行分析,就能判斷計(jì)算機(jī)是否開著,或者這個數(shù)據(jù)包從發(fā)送到返回需要多少時間。 Tracert命令用來跟蹤一個消息從一臺計(jì)算機(jī)到另一臺計(jì)算機(jī)所走的路徑, rusers和finger 通過這兩個命令,你能收集到目標(biāo)計(jì)算機(jī)上的有關(guān)用戶的消息。 掃描器通過選用遠(yuǎn)程TCP/IP不同的端口的服務(wù),并記錄目標(biāo)給予的回答,通過這種方法,可以搜集到很多關(guān)于目標(biāo)主機(jī)的各種有用的信息??傊?,端口掃描”通常指用同一信息對目標(biāo)計(jì)算機(jī)的所有所需掃描的端口進(jìn)行發(fā)送,然后根據(jù)返回端口狀態(tài)來分析目標(biāo)計(jì)算機(jī)的端口是否打開、是否可用?!岸丝趻呙琛毙袨榈囊粋€重要特征,是在短時期內(nèi)有很多來自相同的
4、信源地址,傳向不同的目的、地端口的包。對于用端口掃描進(jìn)行攻擊的人來說,攻擊者總是可以做到在獲得掃描結(jié)果的同時,使自己很難被發(fā)現(xiàn)或者說很難被逆向?qū)ほ櫋榱穗[藏攻擊,攻擊者可以慢慢地進(jìn)行掃描。除非目標(biāo)系統(tǒng)通常閑著(這樣對一個沒有l(wèi)isten()端口的數(shù)據(jù)包都會引起管理員的注意),有很大時間間隔的端口掃描是很難被識別的。隱藏源地址的方法是發(fā)送大量的欺騙性的端口掃描數(shù)據(jù)包(如1 000個),其中只有一個是從真正的源地址來的。這樣即使全部數(shù)據(jù)包都被察覺,被記錄下來,也沒有人知道哪個是真正的信源地址。能發(fā)現(xiàn)的僅僅是“曾經(jīng)被掃描過”的地址。也正因?yàn)檫@樣,那些黑客們才樂此不疲地繼續(xù)大量使用,這種端口掃描技術(shù),
5、來達(dá)到他們獲取目標(biāo)計(jì)算機(jī)信息,并進(jìn)行惡意攻擊的目的。通常進(jìn)行端口掃描的工具目前主要采用的是端口掃描軟件,也稱之為“端口掃描器”。端口掃描器也是一種程序,它可以對目標(biāo)主機(jī)的端口進(jìn)行連接,并記錄目標(biāo)端口的應(yīng)答。端口掃描器通過選用遠(yuǎn)程TCP/IP協(xié)議不同的端口的服務(wù),記錄目標(biāo)計(jì)算機(jī)端口給予回答的方法,可以收集到很多關(guān)于目標(biāo)計(jì)算機(jī)的各種有用信息(比如是否有端口在偵聽,是否允許匿名登錄,是否有可寫的FTP目錄,是否能用Telnet等)。 雖然端口掃描器可以用于正常網(wǎng)絡(luò)安全管理,但就目前來說,它主要還是被黑客所利用,是黑客入侵、攻擊前期不可缺少的工具。黑客一般先使用掃描工具掃描待入侵主機(jī),掌握目標(biāo)主機(jī)的端
6、口打開情況,然后采取相應(yīng)的入侵措施。 無論是正常用途,還是非法用途,端口掃描可以提供4個用途。1.識別目標(biāo)主機(jī)上有哪些端口是開放的,這是端口掃描的最基本目的。2.識別目標(biāo)系統(tǒng)的操作系統(tǒng)類型(Windows、Linux或UNIX等)。3.識別某個應(yīng)用程序或某個特定服務(wù)的版本號。4.識別目標(biāo)系統(tǒng)的系統(tǒng)漏洞,這是端口掃描的一種新功能。 當(dāng)然以上這些功能不可能是一成不變的,隨著技術(shù)的不斷完善,新的功能會不斷地增加。端口掃描器并不是一個直接攻擊網(wǎng)絡(luò)漏洞的程序,它僅僅能幫助發(fā)現(xiàn)目標(biāo)計(jì)算機(jī)的某些內(nèi)在的弱點(diǎn)。一個好的掃描器還能對它得到的數(shù)據(jù)進(jìn)行分析,幫助查找目標(biāo)計(jì)算機(jī)的漏洞。但它不會提供一個系統(tǒng)的詳細(xì)步驟。編
7、寫掃描器程序必須要很多TCP/IP協(xié)議程序,以及C、Perl和SHELL語言的知識,還需要一些Socket編程的背景。四、系統(tǒng)功能描述及軟件模塊劃分主要功能有:1. 使用端口掃描對一臺主機(jī)進(jìn)行掃描,一臺主機(jī)上有哪些端口是打開的;2. 對一個網(wǎng)段進(jìn)行 IP 掃描,顯示出一個網(wǎng)段內(nèi)有哪些主機(jī)是開機(jī)的。軟件所包含的主要模塊有:1.對IP的處理。包括對IP的移位和運(yùn)算等。2.對本機(jī)個端口的掃描。3.對本網(wǎng)段的其他主機(jī)個端口的掃描。五、設(shè)計(jì)步驟六、關(guān)鍵問題及其解決方法 完整的代碼如下: 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("退出程序!"); /讀取輸入結(jié)束ip System.out.println(); System.out.println("請輸入結(jié)束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格式錯誤,請輸入正確的結(jié)束ip:"); else if(Math.abs(xxx2-xxx)>) bool1=false; System.out.println("掃描IP數(shù)不能大于,請輸入正確的結(jié)束ip:"); else bool1=true; catch(IOException e)System.out.println("IP格式錯誤,請輸入正確的結(jié)束ip:"); catch
14、(NumberFormatException e)System.out.println("IP格式錯誤,請輸入正確的結(jié)束ip:"); catch(StringIndexOutOfBoundsException e)System.out.println("IP格式錯誤,請輸入正確的結(jié)束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);/讀取輸入結(jié)束端口 System.out.println(); System.out.println("請輸入結(jié)束端口:"); 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("端口錯誤,請輸入正確的結(jié)束端口:"); bool3=false; else bool3=true; catch(IOException e)System.out.println("端口錯誤,請輸入正確的結(jié)束端口:"); 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);/轉(zhuǎn)換ip long long_endip=Com.ipj(shuendip); int allport=endport-beginport+1;/計(jì)算掃描端口總數(shù) int allip=(int)Math.abs(long_beginip - long_endip) + 1; int t1=0,t2=0; /計(jì)算耗時 long begint,endt,alltime; Date
21、 mydate=new Date(); begint=mydate.getTime(); /獲取當(dāng)前時間 try /計(jì)算兩個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(); /獲取結(jié)束時間 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("主機(jī):"+ghost+" TCP端口:"+scanP+" 在線"); catch(SocketTimeoutException e) catch(IOException e) quanjubianliang.Threadnum=quanjubianliang.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.substring(pos
溫馨提示
- 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 紡紗工藝參數(shù)優(yōu)化與調(diào)整考核試卷
- 幼兒園活動設(shè)計(jì)要點(diǎn)
- 自行車配件市場供需分析考核試卷
- 網(wǎng)絡(luò)安全風(fēng)險(xiǎn)識別與防范考核試卷
- 《卓越發(fā)展》:課件展示
- 刀具的設(shè)計(jì)與性能評估方法考核試卷
- 電力設(shè)備中低壓配電柜設(shè)計(jì)與選型考核試卷
- 收藏品市場調(diào)研報(bào)告撰寫技巧考核試卷
- 航運(yùn)企業(yè)競爭力評價考核試卷
- 節(jié)能環(huán)保與健康城市考核試卷
- 美容美發(fā)開業(yè)慶典總經(jīng)理致辭
- 自身免疫性疾病的新型治療策略
- 江蘇省小學(xué)科學(xué)實(shí)驗(yàn)知識競賽題庫附答案
- 華僑城文旅項(xiàng)目商業(yè)計(jì)劃書
- 老年人誤吸的預(yù)防團(tuán)體標(biāo)準(zhǔn)試題
- 電纜管廊敷設(shè)施工方案及流程
- 中風(fēng)的早期識別和急救處理方法
- pets5歷年真題(口語)
- 2024年廣東省中山市教學(xué)共進(jìn)聯(lián)盟中考一模數(shù)學(xué)試題(含答案)
- 2024年司法考試真題及答案
- 口腔護(hù)士進(jìn)修總結(jié)匯報(bào)
評論
0/150
提交評論