Jump to content
M2G

[Java] IP Range Generator

Recommended Posts

2iicwao.png

Am facut un Generator de ip-uri aflate intre doua intervale.

Rezultatul se salveaza intr-un fisier result.txt in acelasi folder in care este situat executabilul.

Se poate folosi la generarea de ip-uri pentru scan cu Nmap sau la orice altceva il considerati util.

Have fun!

Download: http://www.mediafire.com/download/i137bggwbxa9lq3/IP_Range_Gen_(M2G).jar

Edited by M2G
  • Upvote 1
Link to comment
Share on other sites

o sa ii adaug zilele astea. Eventual fac o versiunea mai complexa care sa scaneze si porturile deschise si sa sorteze ip-urile in functie de porturile deschise. etc, idei sunt dar timp nu prea :)

Codul sursa nu esti dragut sal publici si tu ? asa mai invatam si noi un pic de java.

Link to comment
Share on other sites

Codul sursa nu esti dragut sal publici si tu ? asa mai invatam si noi un pic de java.

E o chestie simpla dar daca vreti sursa, nu o sa ma opun. :))

Problema e ca eu sunt cam lenes sa comentez si documentez codul sursa dar va prindeti voi ce si cum face daca vreti.

Scriu direct aici ca nu e mare.

Main.java

import javax.swing.UIManager;


public class Main {

public static void main(String[] args) {

try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
throw new RuntimeException(e);
}
View interfata = new View();
new Controller(interfata);
}

}

View.java

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JSeparator;
import javax.swing.JButton;
import java.awt.Color;
import javax.swing.SwingConstants;


@SuppressWarnings("serial")
public class View extends JFrame {

private JPanel contentPane;
private JTextField from2;
private JTextField from1;
private JTextField from3;
private JTextField from4;
private JTextField to1;
private JTextField to2;
private JTextField to3;
private JTextField to4;
private JButton btnDoIt;
private JLabel lblstatus;

/**
* Create the frame.
*/
public View() {
setResizable(false);

setTitle("IP Range Generator by M2G");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 433, 300);
contentPane = new JPanel();
contentPane.setBackground(Color.DARK_GRAY);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel lblFrom = new JLabel("From:");
lblFrom.setForeground(Color.GREEN);
lblFrom.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblFrom.setBounds(27, 24, 46, 14);
contentPane.add(lblFrom);

JSeparator separator = new JSeparator();
separator.setBounds(89, 66, 15, 2);
contentPane.add(separator);

JSeparator separator_1 = new JSeparator();
separator_1.setBounds(198, 66, 15, 2);
contentPane.add(separator_1);

JSeparator separator_2 = new JSeparator();
separator_2.setBounds(311, 66, 15, 2);
contentPane.add(separator_2);

JSeparator separator_3 = new JSeparator();
separator_3.setBounds(89, 136, 15, 2);
contentPane.add(separator_3);

JSeparator separator_4 = new JSeparator();
separator_4.setBounds(198, 136, 15, 2);
contentPane.add(separator_4);

JSeparator separator_5 = new JSeparator();
separator_5.setBounds(311, 136, 15, 2);
contentPane.add(separator_5);

from2 = new JTextField();
from2.setBounds(127, 54, 52, 20);
contentPane.add(from2);
from2.setColumns(10);

from1 = new JTextField();
from1.setColumns(10);
from1.setBounds(27, 54, 52, 20);
contentPane.add(from1);

from3 = new JTextField();
from3.setColumns(10);
from3.setBounds(232, 54, 52, 20);
contentPane.add(from3);

from4 = new JTextField();
from4.setColumns(10);
from4.setBounds(336, 54, 52, 20);
contentPane.add(from4);

to1 = new JTextField();
to1.setColumns(10);
to1.setBounds(27, 128, 52, 20);
contentPane.add(to1);

to2 = new JTextField();
to2.setColumns(10);
to2.setBounds(127, 128, 52, 20);
contentPane.add(to2);

to3 = new JTextField();
to3.setColumns(10);
to3.setBounds(232, 128, 52, 20);
contentPane.add(to3);

to4 = new JTextField();
to4.setColumns(10);
to4.setBounds(336, 128, 52, 20);
contentPane.add(to4);

JLabel lblTo = new JLabel("To:");
lblTo.setForeground(Color.GREEN);
lblTo.setFont(new Font("Tahoma", Font.PLAIN, 12));
lblTo.setBounds(27, 103, 46, 14);
contentPane.add(lblTo);

btnDoIt = new JButton("Do It!");
btnDoIt.setBounds(127, 181, 157, 31);
contentPane.add(btnDoIt);

lblstatus = new JLabel("Ready!");
lblstatus.setForeground(Color.GREEN);
lblstatus.setHorizontalAlignment(SwingConstants.CENTER);
lblstatus.setFont(new Font("Tahoma", Font.PLAIN, 13));
lblstatus.setBounds(127, 234, 157, 14);
contentPane.add(lblstatus);
setVisible(true);
validate();
setLocationRelativeTo(null);
}

public JTextField getFrom2() {
return from2;
}

public void setFrom2(JTextField from2) {
this.from2 = from2;
}

public JTextField getFrom1() {
return from1;
}

public void setFrom1(JTextField from1) {
this.from1 = from1;
}

public JTextField getFrom3() {
return from3;
}

public void setFrom3(JTextField from3) {
this.from3 = from3;
}

public JTextField getFrom4() {
return from4;
}

public void setFrom4(JTextField from4) {
this.from4 = from4;
}

public JTextField getTo1() {
return to1;
}

public void setTo1(JTextField to1) {
this.to1 = to1;
}

public JTextField getTo2() {
return to2;
}

public void setTo2(JTextField to2) {
this.to2 = to2;
}

public JTextField getTo3() {
return to3;
}

public void setTo3(JTextField to3) {
this.to3 = to3;
}

public JTextField getTo4() {
return to4;
}

public void setTo4(JTextField to4) {
this.to4 = to4;
}

public JButton getBtnDoIt() {
return btnDoIt;
}

public void setBtnDoIt(JButton btnDoIt) {
this.btnDoIt = btnDoIt;
}

public JLabel getLblstatus() {
return lblstatus;
}

public void setLblstatus(String alblstatus) {
lblstatus.setText(alblstatus);
}
}

Controller.java

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JOptionPane;


public class Controller{
private View interfata;

public Controller(View interfata){
this.interfata = interfata;
interfata.getBtnDoIt().addActionListener(new DoAction());

}

class DoAction implements ActionListener{

public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource() == interfata.getBtnDoIt()){

interfata.setLblstatus("Working...");

String from1 = interfata.getFrom1().getText();
String from2 = interfata.getFrom2().getText();
String from3 = interfata.getFrom3().getText();
String from4 = interfata.getFrom4().getText();

String to1 = interfata.getTo1().getText();
String to2 = interfata.getTo2().getText();
String to3 = interfata.getTo3().getText();
String to4 = interfata.getTo4().getText();



if(isValid(from1) && isValid(from2) && isValid(from3) && isValid(from4) && isValid(to1) && isValid(to2) && isValid(to3) && isValid(to4)){

boolean cont=true;

String temp;
int ifrom1 = Integer.parseInt(from1);
int ifrom2 = Integer.parseInt(from2);
int ifrom3 = Integer.parseInt(from3);
int ifrom4 = Integer.parseInt(from4);

int ito1 = Integer.parseInt(to1);
int ito2 = Integer.parseInt(to2);
int ito3 = Integer.parseInt(to3);
int ito4 = Integer.parseInt(to4);

if (correctInput(ifrom1,ifrom2,ifrom3,ifrom4,ito1,ito2,ito3,ito4)){

try {
BufferedWriter out = new BufferedWriter(new FileWriter("result.txt"));

while(cont) {

temp = ifrom1+"."+ifrom2+"."+ifrom3+"."+ifrom4+"\n";
out.write(temp);
ifrom4++;
if(ifrom4==256){
ifrom4=0;
ifrom3++;
}
if (ifrom3==256){
ifrom3=0;
ifrom2++;
}
if (ifrom2==256){
ifrom2=0;
ifrom1++;
}
if( (ifrom1 == ito1) && (ifrom2 == ito2) && (ifrom3 == ito3) && (ifrom4 == ito4) ) {
temp = ifrom1+"."+ifrom2+"."+ifrom3+"."+ifrom4+"\n";
out.write(temp);
cont = false;
}

}
out.close();
} catch (IOException e) {
}
}


}else JOptionPane.showMessageDialog(null, "Invalid input", "Error", JOptionPane.ERROR_MESSAGE);
interfata.setLblstatus("Done!");
}

}

}


public boolean correctInput(int ifrom1, int ifrom2, int ifrom3, int ifrom4, int ito1, int ito2, int ito3, int ito4){
boolean check=true;
if(ifrom1 <= ito1){
if(ifrom1 == ito1){
if (ifrom2 <= ito2){
if(ifrom2 == ito2){
if(ifrom3 <= ito3){
if(ifrom3 == ito3){
if(ifrom4 <= ito4){

}else {
JOptionPane.showMessageDialog(null, "Please verify the IP range!", "Invalid range", JOptionPane.ERROR_MESSAGE);
check = false;
}
}
}else {
JOptionPane.showMessageDialog(null, "Please verify the IP range!", "Invalid range", JOptionPane.ERROR_MESSAGE);
check = false;
}
}
}else {
JOptionPane.showMessageDialog(null, "Please verify the IP range!", "Invalid range", JOptionPane.ERROR_MESSAGE);
check = false;
}
}
}else {
JOptionPane.showMessageDialog(null, "Please verify the IP range!", "Invalid range", JOptionPane.ERROR_MESSAGE);
check = false;
}
return check;
}


public boolean isValid(String arg){
int test;
try{
test = Integer.parseInt(arg);
}
catch (NumberFormatException ex){
return false;
}
if (test < 0 || test > 255) return false;
else return true;
}

}

plm, imi fute forumul indentarea.

Main.java -> http://pastebin.com/b31TBZba

View.java -> http://pastebin.com/kKC2uTpW

Controller.java -> http://pastebin.com/nsnHrpy0

Edited by M2G
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...