当前位置:首页 » 课程大全 » 获取ip地址课程设计

获取ip地址课程设计

发布时间: 2021-02-18 05:43:58

㈠ 计算机网络课程设计使用ARP协议获取局域网内部活动主机的物理地址java

提供目的设备的Mac地址。例如计算机A和计算机B通讯,计算机A的arp表中,会版有计算机权B的IP及对应计算机B的Mac。同理,计算机B中的arp表也有计算机A的IP及对应计算机A的Mac。可在dos命令框里使用arp —a查看

㈡ 谁有监控IP包流量的课程设计,跪求给一个

㈢ 最近在做一个课设:基于Socket 的局域网聊天工具。请问服务器端和客户端是怎么通过IP地址找到对方的

Server端不是要建立抄serversocket么,这个类会监听socket连接,客户端连接服务端的时候会携带本机(客户端)的ip,服务器接收连接,经过三次握手之后双方建立tcp连接,然后就可以通讯了,编写服务端的时候并不需要关心客户端发起连接的端口。

获取ip:socket.getInetAddress()
获取端口:socket.getPort();

㈣ 计算机网络课程设计《公司局域网设计》或者《校园局域网设计》,按下面的要求

于加深网络模型的各层功能和设计思想的理解

㈤ 用java 编写一个可以实现IP地址查询功能的课程设计

下面是获得本机IP地址的方法,跟你的程序捆绑起来,互相发送消息的时候直接将IP发送过去

private static String[] getAllLocalHostIP(){

List<String> res=new ArrayList<String>();

Enumeration netInterfaces;

try {

netInterfaces = NetworkInterface.getNetworkInterfaces();

InetAddress ip = null;

while (netInterfaces.hasMoreElements()) {

NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();

Enumeration nii=ni.getInetAddresses();

while(nii.hasMoreElements()){

ip = (InetAddress) nii.nextElement();

if (ip.getHostAddress().indexOf(":") == -1) {

res.add(ip.getHostAddress());

}

}

}

} catch (SocketException e) {

e.printStackTrace();

}

return (String[])res.toArray(new String[0]);

}

这是个扫描局域网ip的windows解决方案,在unix系统下可能有问题
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
public class LanIP {

public ArrayList<String> getLanIPArrayList() {

ArrayList<String> arrayIP = null;

try {

InitSystem initSystem = null;

initSystem = new InitSystem();

Thread thread = new Thread(initSystem);

thread.start();

thread.join();

arrayIP = initSystem.getArrayIPUsed();

} catch (UnknownHostException e) {

e.printStackTrace();

} catch (InterruptedException e) {

e.printStackTrace();

}

return arrayIP;

}

private class InitSystem implements Runnable {

private int firstIP = 2;// 查询的 IP 地址的最后一位起始点

private int lastIP = 255;// 查询的 IP 地址的最后一位结束点

private volatile ArrayList<Thread> arrayThread;// 子线程段

private final int MAXTHREADNUM = 30; // 最大同时进行的子线程数量

private int threadNumNow;// 当前正在进行的子线程数量

private volatile ArrayList<String> arrayIP;// 局域网查询所有可能的 IP 地址的结果集

private volatile ArrayList<String> arrayIPUsed;// 局域网查询已经使用的 IP 地址的结果集

private InitSystem(String ip) {

arrayIP = new ArrayList<String>();

arrayIPUsed = new ArrayList<String>();

arrayThread = new ArrayList<Thread>();

setIPAddressList(ip);

}

private InitSystem() throws UnknownHostException {

this(InetAddress.getLocalHost().getHostAddress());

}

private synchronized ArrayList<String> getArrayIPUsed() {

try {

while (arrayIP.size() > 0) {

Thread.sleep(300);

}

} catch (InterruptedException e) {

e.printStackTrace();

}

return arrayIPUsed;

}

private void setIPAddressList(String ip) {

// 根据这个 ip 地址查询它所在的局域网的所有可能 IP 地址的集合

int lastPointIndex = ip.lastIndexOf('.');

String stringIPHead = ip.substring(0, ++lastPointIndex);

String stringIP = null;

for (int i = firstIP; i <= lastIP; i++) {

stringIP = stringIPHead + i;

arrayIP.add(stringIP);

}

}

public void run() {

synchronized (this) {

try {

while (arrayIP.size() > 0) {

while (threadNumNow >= MAXTHREADNUM) {

for (Thread thread : arrayThread) {

if (!thread.getState().equals(

Thread.State.TERMINATED)) {

thread.join(5);

}

--threadNumNow;

}

arrayThread = new ArrayList<Thread>();

}

Thread thread = new Thread(new InnerClass(arrayIP

.remove(0)));

thread.start();

threadNumNow++;

arrayThread.add(thread);

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

private class InnerClass implements Runnable {

// 线程查询一个 IP 是否是可以连接的 是则加入到相应的 IP 数组

private String ip;

private InnerClass(String ip) {

this.ip = ip;

}

private boolean isUsedIPAddress(String ip) {

synchronized (this) {

// 判断这个 IP 地址在当前局域网中是否是可连接的 IP

Process process = null;

BufferedReader bufReader = null;

String bufReadLineString = null;

try {

process = Runtime.getRuntime().exec(

"ping " + ip + " -w 100 -n 1");

bufReader = new BufferedReader(new InputStreamReader(

process.getInputStream()));

for (int i = 0; i < 6 && bufReader != null; i++) {

bufReader.readLine();

}

bufReadLineString = bufReader.readLine();

if (bufReadLineString == null) {

process.destroy();

return false;

}

if (bufReadLineString.indexOf("timed out") > 0

|| bufReadLineString.length() < 17

|| bufReadLineString.indexOf("invalid") > 0) {

process.destroy();

return false;

}

} catch (IOException e) {

e.printStackTrace();

}

process.destroy();

return true;

}

}

public void run() {

synchronized (this) {

if (isUsedIPAddress(ip)) {

arrayIPUsed.add(ip);

}

}

}

}

}

}

热点内容
武汉大学学生会辅导员寄语 发布:2021-03-16 21:44:16 浏览:612
七年级学生作文辅导学案 发布:2021-03-16 21:42:09 浏览:1
不屑弟高考成绩 发布:2021-03-16 21:40:59 浏览:754
大学毕业证会有成绩单 发布:2021-03-16 21:40:07 浏览:756
2017信阳学院辅导员招聘名单 发布:2021-03-16 21:40:02 浏览:800
查询重庆2018中考成绩查询 发布:2021-03-16 21:39:58 浏览:21
结业考试成绩怎么查询 发布:2021-03-16 21:28:40 浏览:679
14中医医师资格笔试考试成绩查分 发布:2021-03-16 21:28:39 浏览:655
名著赏析课程标准 发布:2021-03-16 21:27:57 浏览:881
北京大学商业领袖高端培训课程 发布:2021-03-16 21:27:41 浏览:919