Commit 464cad75 authored by Tanvi's avatar Tanvi

MAC ARP

parents
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/NetworkSecurityGame.iml" filepath="$PROJECT_DIR$/NetworkSecurityGame.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
public class ARPCache {
private String ip_address;
private String hw_type;
private String hw_Address;
private String flags;
private String mask;
private String iFace;
public ARPCache(String ip_address, String hw_type, String hw_Address,
String flags, String mask, String iFace) {
super();
this.ip_address = ip_address;
this.hw_type = hw_type;
this.hw_Address = hw_Address;
this.flags = flags;
this.mask = mask;
this.iFace = iFace;
}
public String getIp_from_Hw(String ip_address)
{
return getHw_Address();
}
public String getHw_from_Ip(String hw_address)
{
return getIp_address();
}
@Override
public String toString() {
return "ARPCache [ip_address=" + ip_address + ", hw_type=" + hw_type
+ ", hw_Address=" + hw_Address + "]";
}
public String getIp_address() {
return ip_address;
}
public void setIp_address(String ip_address) {
this.ip_address = ip_address;
}
public String getHw_type() {
return hw_type;
}
public void setHw_type(String hw_type) {
this.hw_type = hw_type;
}
public String getHw_Address() {
return hw_Address;
}
public void setHw_Address(String hw_Address) {
this.hw_Address = hw_Address;
}
public String getFlags() {
return flags;
}
public void setFlags(String flags) {
this.flags = flags;
}
public String getMask() {
return mask;
}
public void setMask(String mask) {
this.mask = mask;
}
public String getiFace() {
return iFace;
}
public void setiFace(String iFace) {
this.iFace = iFace;
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.ImageObserver;
import java.text.AttributedCharacterIterator;
import java.util.ArrayList;
import java.util.List;
public class ARPDemo extends JApplet {
JButton b;
JTextField tf;
List<Packet> packets = new ArrayList<>();
ImageIcon nodeimg = new ImageIcon("/home/tanvi/Pictures/cmp.png");
public ARPDemo(){
paint(new Graphics() {
@Override
public Graphics create() {
return null;
}
@Override
public void translate(int x, int y) {
}
@Override
public Color getColor() {
return null;
}
@Override
public void setColor(Color c) {
}
@Override
public void setPaintMode() {
}
@Override
public void setXORMode(Color c1) {
}
@Override
public Font getFont() {
return null;
}
@Override
public void setFont(Font font) {
}
@Override
public FontMetrics getFontMetrics(Font f) {
return null;
}
@Override
public Rectangle getClipBounds() {
return null;
}
@Override
public void clipRect(int x, int y, int width, int height) {
}
@Override
public void setClip(int x, int y, int width, int height) {
}
@Override
public Shape getClip() {
return null;
}
@Override
public void setClip(Shape clip) {
}
@Override
public void copyArea(int x, int y, int width, int height, int dx, int dy) {
}
@Override
public void drawLine(int x1, int y1, int x2, int y2) {
}
@Override
public void fillRect(int x, int y, int width, int height) {
}
@Override
public void clearRect(int x, int y, int width, int height) {
}
@Override
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
}
@Override
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
}
@Override
public void drawOval(int x, int y, int width, int height) {
}
@Override
public void fillOval(int x, int y, int width, int height) {
}
@Override
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
}
@Override
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
}
@Override
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
}
@Override
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
}
@Override
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) {
}
@Override
public void drawString(String str, int x, int y) {
}
@Override
public void drawString(AttributedCharacterIterator iterator, int x, int y) {
}
@Override
public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
return false;
}
@Override
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
return false;
}
@Override
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
return false;
}
@Override
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) {
return false;
}
@Override
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) {
return false;
}
@Override
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) {
return false;
}
@Override
public void dispose() {
}
});
}
public void paint(Graphics g)
{
// Draw head
final Node na = new Node(1);
na.setNode_name("Node A");
InterfaceConfig ica = new InterfaceConfig("10.1.0.1 (IP1)",
"32:52:5e:4b:7a:e4 (MAC1)","10.1.0.255","255.255.255.0","ether");
na.setInterfaceConfig(ica);
na.setHaveAccess(false);
final Node nb = new Node(2);
nb.setNode_name("Node B");
InterfaceConfig icb = new InterfaceConfig("10.1.0.2 (IP2)",
"b8:92:a7:e2:9c:01 (MAC2)","10.1.0.255","255.255.255.0","wlan");
nb.setInterfaceConfig(icb);
nb.setHaveAccess(false);
final Node nc = new Node(3);
nc.setNode_name("Node C");
InterfaceConfig icc = new InterfaceConfig("10.1.0.3 (IP3)",
"95:ae:93:d4:a7:9c (MAC3)","10.1.0.255","255.255.255.0","ether");
nc.setInterfaceConfig(icc);
nc.setHaveAccess(true);
List<ARPCache> ac = new ArrayList<>();
ac.add(new ARPCache("10.1.0.1 (IP1)", "ether", "32:52:5e:4b:7a:e4 (MAC1)","", "",""));
ac.add(new ARPCache("10.1.0.2 (IP2)", "wlan", "b8:92:a7:e2:9c:01 (MAC2)","", "",""));
ac.add(new ARPCache("10.1.0.3 (IP3)", "ether", "95:ae:93:d4:a7:9c (MAC3)","", "",""));
na.setArpCaches(ac);
nb.setArpCaches(ac);
nc.setArpCaches(ac);
Network network = new Network("Network 1");
List<Node> nodes = new ArrayList<>();
nodes.add(na); nodes.add(nb); nodes.add(nc);
network.setNodes(nodes);
network.setNo_of_nodes(nodes.size());
network.setPackets(packets);
JFrame frame= new JFrame("SIMULATOR");
JPanel panel = new JPanel(null){
public void paintComponent(Graphics g){
g.drawLine(320,380,720,380); //a b
g.drawLine(280,320,420,150); //a c
g.drawLine(620,150,720,320); //b c
}
};
JLabel l1,l2,l3,title;
JLabel transmitting;
transmitting = new JLabel("");
final JButton b1,b2,b3;
title = new JLabel("RIGHT CLICK ON THE NODE TO PERFORM ACTIONS. You have access of Node C.");
title.setBounds(10,10,700,30);
l1=new JLabel(na.getNode_name());
l1.setBounds(200,500, 100,30);
l1.addMouseListener(new PopClickListener(na,network,panel));
l2=new JLabel(nb.getNode_name());
l2.setBounds(800,500, 100,30);
l2.addMouseListener(new PopClickListener(nb,network,panel));
l3=new JLabel(nc.getNode_name());
l3.setBounds(500,250, 100,30);
l3.addMouseListener(new PopClickListener(nc,network,panel));
JButton button;
button = new JButton("START TRAMISSION");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// packets.add(new Packet(na.getInterfaceConfig().getIp_address(),nb.getInterfaceConfig().getIp_address(),
// na.getInterfaceConfig().getMac_address(),nb.getInterfaceConfig().getMac_address(),"HELLO", "Data Packet"));
/* packets.add(new Packet(na.getInterfaceConfig().getIp_address(),na.getInterfaceConfig().getMac_address(),
na.getArpcache()))\*/
for(int i=0;i<na.getArpCaches().size();i++)
{
if(na.getArpCaches().get(i).getIp_address() == nb.getInterfaceConfig().getIp_address())
{
packets.add(new Packet(na.getInterfaceConfig().getIp_address(),na.getArpCaches().get(i).getIp_address(),
na.getInterfaceConfig().getMac_address(),na.getArpCaches().get(i).getHw_Address(),"HELLO","Data Packet"));
}
}
network.setPackets(packets);
JOptionPane.showMessageDialog(frame, na.getNode_name()+ " Trasmitting to " + nb.getNode_name());
System.out.print(packets);
}
});
button.setBounds(400,650,300,30);
JLabel n1,n2,n3;
n1 = new JLabel("");
n1.setIcon(nodeimg); n1.setBounds(120,300, 200,200);
n1.addMouseListener(new PopClickListener(na,network,panel));
n2 = new JLabel("");
n2.setIcon(nodeimg); n2.setBounds(720,300, 200,200);
n2.addM