Israel's Profile User Rating: -----

Reputation: 7 Worker
Group:
Authors
Active Posts:
818 (0.22 per day)
Joined:
22-November 04
Profile Views:
10,594
Last Active:
User is offline Nov 14 2014 08:29 PM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Linux
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
Playstation
Your Car:
Mitsubishi
Dream Kudos:
200

Latest Visitors

Icon   Israel In /dev/null no one can hear you scream...

Posts I've Made

  1. In Topic: Regex Causing "list index out of range" Error

    Posted 28 Feb 2014

    That dawned on me while I was away for my computer a couple hours.

    Good call though. Derp!
  2. In Topic: Regex Causing "list index out of range" Error

    Posted 28 Feb 2014

    I see what you mean. I took out the [^127.0.0.1] like so:

    #!/usr/bin/python
    
    import re
    import subprocess
    from subprocess import Popen, PIPE
    
    pattern = re.compile(r'inet.*\d+\.\d+\.\d+\.\d+')
    
    p1 = Popen(["/sbin/ifconfig"], stdout=subprocess.PIPE)
    
    output = p1.communicate()[0]
    result = re.findall(pattern, output)
    
    print result[0]
    


    And a line with 127.0.0.1 is all I get:

    # ./test.py 
    inet addr:127.0.0.1  Mask:255.0.0.0
    


    Would you happen to know why its finding 127.0.0.1, but missing 10.0.0.139 listed on my other interface?

    wlan2     Link encap:Ethernet  HWaddr 00:1f:1f:7e:a3:de  
              inet addr:10.0.0.139  Bcast:10.0.0.255  Mask:255.255.255.0
              inet6 addr: fe80::21f:1fff:fe7e:a3de/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:19712 errors:0 dropped:0 overruns:0 frame:0
              TX packets:17179 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:14323745 (13.6 MiB)  TX bytes:3351821 (3.1 MiB)
    


    Thanks for getting me this far.
  3. In Topic: Code adding a new line when it shouldn't...

    Posted 22 Feb 2014

    Nice! Guess I have a lot more to learn about debugging with Python. The "from array import *" was something I found searching for arrays, but it seems to work fine without it. Thank you both!
  4. In Topic: Android/Eclipse - "R cannot be resolved to a variable"

    Posted 22 Feb 2014

    I tried closing and re-opening the project and removing it completely and trying again. Also tried installing Eclipse and the Android-SDK on another machine. I tried Clean->Build, with and without "import android.R;" with no luck. How would I import this from my package instead of from Android?
  5. In Topic: Trouble with multiple threads in C

    Posted 4 Jan 2014

    Well, I added one on line 121 of this, but I'm still not seeing anything.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <pthread.h>
    #include <sys/types.h>
    #include <sys/wait.h>
    
    //  gcc -Wall test.c -o test -lpthread --std=c11
    
    int spawn (char* program, char** arg_list)
    {
        pid_t child_pid;
    
        /* Duplicate this process. */
        child_pid = fork ();
    
        if (child_pid != 0){
          /* This is the parent process. */
          return child_pid;
        }
        else {
          /* Now execute PROGRAM, searching for it in the path. */
          execvp (program, arg_list);
          /* The execvp function returns only if an error occurs. */
          fprintf (stderr, "An error occurred in execvp\n");
          abort ();
        }
    }
    
    pthread_t tid[2];
    
    void* doSomeThing(void *arg)
    {
        char **argv = arg;
        //unsigned long i = 0;
        pthread_t id = pthread_self();
    
        if(pthread_equal(id,tid[0]))
        {
             int child_status;
    
             // The argument list to pass to the “dig” command. 
    	 char* arg_list[] = {
    	 "dig", // argv[0], the name of the program. 
    	 "A",
    	 "+short",
    	 NULL  // The argument list must end with a NULL.
             };
    
    	 arg_list[1] = malloc( strlen(argv[1]) + 1 );
    	 strcpy( arg_list[1], argv[1] );
    	 
    	 char* rootns[] = {
    	 "@a.root-servers.net",
    	 "|",
    	 "awk",
    	 "'/^A/", 
    	 "{",
    	 "print", 
    	 "$2",
    	 "}'",
    	 "&&",
    	 "exit",
    	 NULL
    	 };
    	 
    	 rootns[1] = malloc( strlen(rootns[1]) + 1 );
    	 strcat(arg_list[1], rootns[1]);
    	 //strcpy(arg_list[1], rootns[1]);
    	 
    	 /* Spawn a child process running the “ls” command.
    	    Ignore the returned child process ID. */
    	    spawn ("dig", arg_list);
    	    /* Wait for the child process to complete. */
    	    wait (&child_status);
    	    if (WIFEXITED (child_status)){
    	     // printf("dig A +short %s @*.root-servers.net\n", argv[1]);
    	      WEXITSTATUS (child_status);
    	    }
    	    else{
    	      printf("the child process exited abnormally\n");
    	    }
    
        }
        
    	 //strcpy(arg_list[1], rootns[1]);
        //else if(pthread_equal(id,tid[1])){
        else if(pthread_equal(id,tid[1])){
            int child_status3;
    
    	 // The argument list to pass to the “ls” command. 
    	 char* arg_list3[] = {
    	 "dig", // argv[0], the name of the program. 
    	 "A",
    	 "+short",
    	 NULL  // The argument list must end with a NULL.
    	 };
    
    	 arg_list3[1] = malloc( strlen(argv[1]) + 1 );
    	 strcpy( arg_list3[1], argv[1] );
    
             char* rootns3[] = {
    	 "@c.root-servers.net",
    	 "|",
    	 "awk",
    	 "'/^A/",
    	 "{",
    	 "print",
    	 "$2",
    	 "}'",
    	 NULL
    	 };
    
    	 rootns3[1] = malloc( strlen(rootns3[1]) + 1 );
    	 strcat(arg_list3[1], rootns3[1]);
    
    	 // Spawn a child process running the “ls” command.
    	 // Ignore the returned child process ID. 
    	 spawn ("dig", arg_list3);
    	 printf("%s\n", rootns3[1]);
             // Wait for the child process to complete. 
    	 wait (&child_status3);
    	 if(WIFEXITED (child_status3)){
    	    WEXITSTATUS (child_status3);
    	}
    	else{
    	   printf("the child process exited abnormally\n");
    	} 
        }
        else
        {
             int child_status2;
    
             // The argument list to pass to the “ls” command. 
             char* arg_list2[] = {
             "dig", // argv[0], the name of the program. 
             "A",
             "+short",
             NULL  // The argument list must end with a NULL.
             };
    
             arg_list2[1] = malloc( strlen(argv[1]) + 1 );
             strcpy( arg_list2[1], argv[1] );
    
             char* rootns2[] = {
             "@b.root-servers.net",
             "|",
             "awk",
             "'/^A/",
             "{",
             "print",
             "$2",
             "}'",
    	 "&&",
    	 "exit",
             NULL
             };
    
             rootns2[1] = malloc( strlen(rootns2[1]) + 1 );
             strcat(arg_list2[1], rootns2[1]);
    
             /* Spawn a child process running the “ls” command.
                Ignore the returned child process ID. */
                spawn ("dig", arg_list2);
                /* Wait for the child process to complete. */
                wait (&child_status2);
                if (WIFEXITED (child_status2)){
                  //printf("dig A +short %s @*.root-servers.net\n", argv[1]);
                  WEXITSTATUS (child_status2);
                }
                else{
                  printf("the child process exited abnormally\n");
                }
    
    
        }
        for(int i=0; i<(0xFFFFFFFF);i++);
        printf("No loop...\n");
    
        return NULL;
    }
    
    int main (int argc, char* argv[]) {
    
      if(argc < 2 || argc >= 3){
    
        printf("Usage: ./program domain.com\n");
        return 0;
      }
    
      system("setterm -cursor off; clear");
    
      /* Pass argv to a real string.
      char domain[90];
      strcpy(domain, argv[1]);
      printf("the domain is %s\n", domain);*/
    
      int i = 0;
      int err;
    
      printf("dig A +short %s @*.root-servers.net\n", argv[1]);
    
      while(i < 2)
      {
          err = pthread_create(&(tid[i]), NULL, &doSomeThing, argv);
        if (err != 0)
          printf("\ncan't create thread :[%s]", strerror(err));
        else
          i++;
      }
    
      system("setterm -cursor on");
    
      //!! you MUST have this if you're not waiting for all the spawned
      //!! threads to exit.  Otherwise the whole process dies at the return
      //!! from main, regardless of whatever the threads are up to.
      pthread_exit(NULL);
    
      return 0;
    }
    
    


    Is the problem in the char array itself...?

My Information

Member Title:
D.I.C Addict
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Hell
Years Programming:
8
Programming Languages:
C, Python, Perl, Ruby, Bash HTML, CSS, PHP, MySQL

Contact Information

E-mail:
Click here to e-mail me

Comments

Israel has no profile comments yet. Why not say hello?