Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use Gtk2 -init;
- use Gtk2::GladeXML;
- use UI::Dialog;
- use UI::Dialog::Backend::Zenity;
- use Cwd qw(realpath);
- unless($> == 0){
- my $fullpath = realpath($0);
- system("/usr/bin/gksu -u root \"$fullpath\"");
- die("You must be root for use macchanger-gtk\n");
- }
- my($programa, $ventanas_dialogs, $ventana_principal, $ventana_informacion, $ventana_acerca, $combobox_newmac_style, $entrada_specific_mac, $etiqueta_specific_mac, $combobox_iface, $etiqueta_vieja_mac, $etiqueta_nueva_mac, $lista, $vista_texto, $vista_texto1, $etiqueta_mac, $entrada_combobox_iface);
- if(-e 'glade/macchanger-gtk.glade' ){
- $programa = Gtk2::GladeXML->new('glade/macchanger-gtk.glade');
- }else{
- $programa = Gtk2::GladeXML->new('/usr/share/macchanger-gtk/macchanger-gtk.glade');
- }
- $ventanas_dialogs = new UI::Dialog::Backend::Zenity(title => "Gbackground",
- height => 45,
- width => 50,
- listheight => 5,
- order => [ 'zenity', 'xdialog', 'gdialog'] );
- &cargar_widgets;
- &interfaces_disponibles;
- $programa->signal_autoconnect_from_package('main');
- $ventana_principal->show_all();
- &esconder;
- Gtk2->main;
- sub cargar_widgets {
- $ventana_principal = $programa->get_widget('ventana_principal');
- $entrada_specific_mac = $programa->get_widget('entrada_specific_mac');
- $etiqueta_specific_mac = $programa->get_widget('etiqueta_specific_mac');
- $combobox_newmac_style = $programa->get_widget('combobox_newmac_style');
- $ventana_acerca = $programa->get_widget('ventana_acerca');
- $combobox_iface = $programa->get_widget('combobox_iface');
- $ventana_informacion = $programa->get_widget('ventana_informacion');
- $etiqueta_vieja_mac = $programa->get_widget('etiqueta_vieja_mac');
- $etiqueta_nueva_mac = $programa->get_widget('etiqueta_nueva_mac');
- $entrada_combobox_iface = $programa->get_widget('entrada_combobox_iface');
- $etiqueta_mac = $programa->get_widget('etiqueta_mac');
- $lista = $programa->get_widget('lista_de_vendedores');
- $vista_texto = $programa->get_widget('vista_texto');
- $vista_texto1 = $programa->get_widget('vista_texto1');
- }
- sub mac {
- my $interfaz = $entrada_combobox_iface->get_text();
- if(@_[0] eq "solo_mac"){
- open(ARCHIVO, "/sys/class/net/$interfaz/address");
- my $mac_actual;
- while(<ARCHIVO>){
- $mac_actual = $_;
- }
- close(ARCHIVO);
- return $mac_actual;
- }
- open(ARCHIVO, "/sys/class/net/$interfaz/address");
- while(<ARCHIVO>){
- $etiqueta_mac->set_markup("Now your MAC in <b>$interfaz</b> is: <span foreground=\"blue\">$_</span>");
- }
- close(ARCHIVO);
- }
- sub on_boton_cambiar_mac_clicked {
- my $interfaz = &captura_de_informacion;
- my $commande = "ifconfig $interfaz down";
- my $resultat = system($commande);
- if($interfaz eq 'lo' || $interfaz eq 'sit0'){
- $ventanas_dialogs->error(title => "Error, interface unsopported", text => 'This interface don\'t support change the MAC Address');
- return $ventana_principal->show_all;
- }
- my $activo = $combobox_newmac_style->get_active();
- return 0 if $interfaz == 1;
- my($resultado, @posible_error);
- chomp($resultado = `/usr/bin/macchanger --endding $interfaz`) if($activo == 0);
- chomp($resultado = `/usr/bin/macchanger --another $interfaz`) if($activo == 1);
- chomp($resultado = `/usr/bin/macchanger -A $interfaz`) if($activo == 2);
- chomp($resultado = `/usr/bin/macchanger --random $interfaz`) if($activo == 3);
- if($activo == 4){
- my $nueva_mac = $entrada_specific_mac->get_text();
- if($nueva_mac eq ''){
- $ventanas_dialogs->error(title => "Error, not MAC Address", text => 'Please write a MAC Address that yo want change');
- return $ventana_principal->show_all;
- }
- if($nueva_mac =~ /^\w\w:\w\w:\w\w:\w\w:\w\w:\w\w$/){
- chomp($resultado = `/usr/bin/macchanger --mac $nueva_mac $interfaz`);
- }else{
- $ventanas_dialogs->error(title => "Error, MAC Address incorrect", text => 'The MAC Address is incorrect please write a correct MAC Address');
- return $ventana_principal->show_all;
- }
- }
- if($resultado eq /set device name: No such device/){
- $ventanas_dialogs->error(title => "Error, don\'t exist network interface", text => 'Please give a correct network interface because it don\'t exist or is up. The interface <b>must</b> be down');
- } elsif($resultado eq /.*interface up or not permission.*/){
- $ventanas_dialogs->error(title => "Error, Operation not permitted", text => 'Error, probably you don\'t have permission. Are you root?');
- }
- else{
- my @mac = split('\n', $resultado);
- $etiqueta_vieja_mac->set_markup("<span foreground=\"red\">@mac[0]</span>");
- $etiqueta_nueva_mac->set_markup(" <span foreground=\"blue\">@mac[1]</span>");
- &mac;
- $ventana_informacion->show_all;
- }
- my $commande = "ifconfig $interfaz up";
- my $resultat = system($commande);
- }
- sub interfaces_disponibles {
- my @archivos = </sys/class/net/*>;
- my @interfaces;
- foreach my $archivo (@archivos) {
- my @basurita = split(/\//, $archivo);
- next if ($basurita[4] eq "lo" || $basurita[4] eq "sit0");
- push (@interfaces, @basurita[4]);
- }
- foreach (@interfaces) {
- $combobox_iface->append_text("$_");
- }
- }
- sub captura_de_informacion {
- my $interfaz = $entrada_combobox_iface->get_text();
- return $interfaz if($interfaz);
- $ventanas_dialogs->error(title => "Error, not network interface", text => 'Please give the network interface that you want change the MAC address');
- return 1;
- }
- sub esconder {
- $entrada_specific_mac->hide();
- $etiqueta_specific_mac->hide();
- }
- sub on_combobox_newmac_style_changed {
- my $activo = $combobox_newmac_style->get_active();
- if($activo == 4){
- $entrada_specific_mac->show_all();
- $etiqueta_specific_mac->show_all();
- } else{
- $entrada_specific_mac->hide();
- $etiqueta_specific_mac->hide();
- }
- }
- sub on_boton_mac_actual_clicked {
- my $mac = &mac('solo_mac');
- my $interfaz = $entrada_combobox_iface->get_text();
- if ($interfaz eq ""){
- $ventanas_dialogs->error(title => "Error, not network interface", text => 'Please give the network interface that you show the MAC address');
- } else {
- $ventanas_dialogs->msgbox(title => "Actual MAC of $interfaz", text => "The actual MAC of $interfaz inface is: <span foreground=\"red\">$mac</span>");
- }
- }
- sub on_boton_lista_clicked {
- my $buffer = Gtk2::TextBuffer->new;
- open(LISTA, '/usr/share/macchanger/OUI.list');
- while(<LISTA>){
- $buffer->insert_at_cursor("$_");
- }
- close(LISTA);
- $vista_texto->set_buffer($buffer);
- $buffer = Gtk2::TextBuffer->new;
- open(LISTA, '/usr/share/macchanger/wireless.list');
- while(<LISTA>){
- $buffer->insert_at_cursor("$_");
- }
- close(LISTA);
- $vista_texto1->set_buffer($buffer);
- $lista->show_all;
- }
- sub on_ventana_acerca_close {
- $ventana_acerca->hide;
- }
- sub on_ventana_acerca_delete_event {
- my $w = shift;
- $w->hide;
- 1;
- }
- sub on_lista_de_vendedores_delete_event {
- my $w = shift;
- $w->hide;
- 1;
- }
- sub on_ventana_acerca_response {$ventana_acerca->hide;}
- sub on_boton_aceptar_lista_vendedores_clicked {$lista->hide();}
- sub on_boton_abrir_lista_vendedores_clicked {$lista->show_all;}
- sub on_boton_salir_clicked {Gtk2->main_quit}
- sub on_ventana_principal_delete_event {Gtk2->main_quit}
- sub on_boton_salir_menu_activate {Gtk2->main_quit}
- sub on_boton_acercade_menu_activate {$ventana_acerca->show_all();}
- sub on_boton_aceptar_ventana_informacion_clicked {$ventana_informacion->hide();}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement