-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.py
127 lines (110 loc) · 4.36 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import socket
import time
import sys
try:
import pymysql
pymysql.install_as_MySQLdb()
db = pymysql.connect()
except ImportError:
pass
s = socket.socket()
print(" ------------SQL PITTY CLIENT LITE ------------ \
\n write SQL code on the go \
\n /Code cheza kiwewe/ \
\n ------- Connect only to your SQL server ------- \
\n HELP :\
\n 1.Username and Password required for login to database \
\n 2.'root' is default username for most databases \
\n 3.Leave password blank if database has no password \
\n 4.Bug or Errors [email protected]\
\n 5.Make sure Your phpmyAdmin allows remote conections \
\n ***Happy Querying***")
class sock:
def hostPort(self):
self.host = str(input("REMOTE/LOCAL SERVER IP : "))
self.port = [int(input("PORT TO CONNECT : "))]
# Establishing connection to remote address,checks if the address can recieve a connection
def connect(self):
sec = 0
if(self.host != 0) and (self.port != 0):
while sec < 10:
try:
s.connect((self.host, self.port))
print("Connected successfully to", self.host)
s.close()
sock.checkSQL(self)
break
# 10 reconnection attempts before program terminates
except:
sec += 1
print("an ERROR occured find relatable info : ", sys.exc_info()[
0], "\n Can't connect to remote address \n Reconnecting...")
sock.reconnect(self)
else:
print("ERROR : Transmit failed. Write a valid address \n")
option = input("Press 'y' to exit ")
if (option == 'y'):
exit(-1)
else:
print("restart program please")
def reconnect(self):
time.sleep(5)
try:
s.connect((self.host, self.port))
print("connected successfully to", self.host)
s.close()
except:
print("ERROR : Cant connect to server")
# Random check if phpMyAdmin is installed on remote address
def checkSQL(self):
host = self.host
print("Making sure phpMyAdmin is installed in server\
\n Program will terminate if its not correctly installed.")
try:
c = open("host/phpMyAdmin/config.inc.php", 'r', encoding='utf-8')
s = open("host/phpMyAdmin/sql.php", 'r', encoding='utf-8')
v = open("host/phpMyAdmin/version_check.php",
'r', encoding='utf-8')
i = open("host/phpMyAdmin/index.php", 'r', encoding='utf-8')
if (c.seekable()) and (s.seekable()) and (v.seekable) and (i.seekable()):
print("phpMyAdmin installed")
else:
print("phpMyAdmin not installed")
exit(-1)
sock.database(self)
finally:
c.close()
s.close()
v.close()
i.close()
# establishng connection to database
def database(self):
time.sleep(5)
user = str(input("Enter user name :"))
pwsd = str(input("enter password : "))
db_name = input("Enter database name")
try:
db(self.host, user, pwsd, db_name)
cursor = db.cursor()
cursor.execute("SELECT VERSION();")
data = cursor.fetchone()
print("Connected Succesfully to ", db_name, " via host ", self.host, "\
\n ---WELCOME---\
\n Your Database Version is %s : " % data)
sql = raw_input("DB|", db_name, "|#> ")
# check this part
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
print("oops! this ", MySQLdb.exc_info()[
0], " occurred find relatable info")
except:
print("an ERROR occured find relatable info",
MySQLdb.exc_info()[0], "\n Terminating")
exit(-1)
db.close()
newConnection = sock()
newConnection.hostPort()
newConnection.connect()