#include <mysql.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *dns[10]={"8.8.8.8","172.17.112.2","176.107.220.1","176.107.216.1","91.242.164.1","81.163.80.1","91.247.152.1","91.247.156.1","91.247.156.1","188.254.37.250"};
int cntmas=10;
void GetDNSByUrl(char*dnsname,char*urlname){
FILE *f;
int c;
char *sm = "";
char *estr;
char str[50];
int i;
int pz;
int cod;
int flag;
char ip[50];
char zx[50];
char comstring[200];
strcpy(comstring,"");
strcat(comstring,"dig @");
strcat(comstring,dnsname);
strcat(comstring," ");
strcat(comstring,urlname);
strcat(comstring," +noall +answer >>tmpdns");
system(comstring);
};
int main (void){
MYSQL *conn;
MYSQL *conn2;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "erfwerfwe";
char *database = "webuser";
char *curdns;
char *id;
char sql[200];
int i;
int col;
conn = mysql_init(NULL);
printf ("-Connect Mysql 1\n");
if (!mysql_real_connect(conn, server,user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
conn2 = mysql_init(NULL);
printf ("-Connect Mysql 2\n");
if (!mysql_real_connect(conn2, server,user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
L3:
col=0;
printf ("-Select urls from Mysql\n");
if (mysql_query(conn, "select * from reestrban where type='url' and status=0 limit 1")) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
res = mysql_use_result(conn);
char *urlip;
while ((row = mysql_fetch_row(res)) != NULL){
col++;
printf ("-- URL:");
id=row[0];
urlip=row[1];
printf("%s\n",urlip);
for (i=0;i<cntmas;i++){
curdns=dns[i];
printf ("--- %s\n",curdns);
GetDNSByUrl(curdns,urlip);
};
//обновляем статус что "посмотрели"
strcpy(sql,"update reestrban set status=1 where id=");
strcat(sql,id);
if (mysql_query(conn2, sql)) {
fprintf(stderr, "Error %s\n", mysql_error(conn2));
fprintf(stderr, "Error %s\n", sql);
exit(1);
}
};
if (col!=0) goto L3;
mysql_free_result(res);
mysql_close(conn);
}