def getResult(url):
    #Importing dataset
    #   data = np.loadtxt("dataset.csv", delimiter = ",")

    #Seperating features and labels
    #   X = data[: , :-1]
    #   y = data[: , -1]

    #Seperating training features, testing features, training labels & testing labels
    # X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2)
    # clf = rfc()
    clf = pickle.load(open("model/Nearest Neighbors.sav", 'rb'))
    #clf.fit(X_train, y_train)
    #score = clf.score(X_test, y_test)
    #print(score*100)
    X_new = []
    X_input = url
    X_new = feature_extraction.generate_data_set(X_input)
    X_new = np.array(X_new).reshape(1, -1)

    try:
        prediction = clf.predict(X_new)
        if prediction == -1:
            return "Phishing Url"
        else:
            return "Legitimate Url"
    except:
        return "Phishing Url"
def getResult(url):

    #Importing dataset 
    filen = 'dataset.csv'
    r = open(filen,'rt')
    data = np.loadtxt(r, delimiter = ",") # loading the dataset

    #lets seperating features and labels
    X = data[: , :-1]
    y = data[: , -1]

    #Seperating training features, testing features, training labels & testing labels
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2)
    clf = rfc()
    clf.fit(X_train, y_train)
    score = clf.score(X_test, y_test)
    print(score*100)  # accuracy score

    X_new = []

    X_input = url # checking for catogery
    X_new=feature_extraction.generate_data_set(X_input) # extracting features of given url
    X_new = np.array(X_new).reshape(1,-1)  # converting 

    try:
        prediction = clf.predict(X_new)
        if prediction == -1:
            return "Omg!!!.. its Phishing Url"
        else:
            return "hureeh!!....its a Genuine Url"
    except:
        return "Omg!!... its a Phishing Url"
def getResult(url):
    dataset=pd.read_csv(r"phishing_dataset.csv")
    dataset.drop(['index'],axis=1,inplace=True)
    x=dataset.iloc[: ,0:30].values
    y=dataset.iloc[: ,30:31].values
    from sklearn.model_selection import train_test_split
    x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=0)

    
    from sklearn.tree import DecisionTreeClassifier
    classifier=DecisionTreeClassifier(random_state=0)
    classifier.fit(x_train,y_train)
    decisiontree=classifier.predict(x_test)
    #from sklearn.metrics import confusion_matrix
    #cm=confusion_matrix(y_test,decisiontree)
    #import sklearn.metrics as metrics
    #fpr,tpr,threshold=metrics.roc_curve(y_test,decisiontree)
    #roc_auc=metrics.auc(fpr,tpr)
    accuracy=accuracy_score(decisiontree,y_test)
    print(accuracy*100)
    
    x_new = []
    x_input = url
    x_new=feature_extraction.generate_data_set(x_input)
    x_new = np.array(x_new).reshape(1,-1)
    try:
        prediction = classifier.predict(x_new)
        if prediction == -1:
            return "Phishing URL"
        else:
            return "Legitimate URL"
    except:
        return "Phishing URL"
def getResult(url):

    #Importing dataset
    """data = np.loadtxt(r"dataset/dataset.csv", delimiter = ",")

    #Seperating features and labels
    X = data[: , :-1]
    y = data[: , -1]

    #Seperating training features, testing features, training labels & testing labels
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2)
    clf = rfc()
    clf.fit(X_train, y_train)
    score = clf.score(X_test, y_test)
    #print(score*100)

    pickle.dump(clf,open('model_random_forest.pkl','wb'))"""

    model = pickle.load(open(r'trained-model/model_random_forest.pkl', 'rb'))

    X_new = []

    X_input = url
    X_new = feature_extraction.generate_data_set(X_input)
    X_new = np.array(X_new).reshape(1, -1)

    try:
        prediction = model.predict(X_new)
        if prediction == -1:
            return "Phishing Website"
        else:
            return "Legitimate Website"
    except:
        return "Phishing Website"
Example #5
0
def predict(url):
    '''
    #Importing dataset
    data = np.loadtxt("dataset.csv", delimiter = ",")

    #Seperating features and labels
    X = data[: , :-1]
    y = data[: , -1]

    #Seperating training features, testing features, training labels & testing labels
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2)
    clf = rfc()
    clf.fit(X_train, y_train)
    score = clf.score(X_test, y_test)
    print(score*100)
    with open('rfc.pkl', 'wb') as model_file:
        pickle.dump(clf, model_file)
    '''
    with open('rfc.pkl', 'rb') as model_file:
        model = pickle.load(model_file)

    X_new = []

    X_input = url
    X_new = feature_extraction.generate_data_set(X_input)
    X_new = np.array(X_new).reshape(1, -1)

    try:
        prediction = model.predict(X_new)
        if prediction == -1:
            return 1
        else:
            return 0
    except:
        return 1
def getResult(url):

    #Importing dataset
    data = pd.read_csv('Dataset/dataset.csv', delimiter=",")

    #Seperating features and labels
    X = np.array(data.iloc[:, :-1])
    y = np.array(data.iloc[:, -1])

    print(type(X))
    #Seperating training features, testing features, training labels & testing labels
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    # classifier = RandomForestClassifier()
    classifier = LogisticRegression()
    classifier.fit(X_train, y_train)
    score = classifier.score(X_test, y_test)
    score = score * 100
    print(score)

    X_new = []

    X_input = url
    X_new = feature_extraction.generate_data_set(X_input)
    X_new = np.array(X_new).reshape(1, -1)

    analysis_result = ""

    try:
        prediction = classifier.predict(X_new)
        if prediction == -1:
            analysis_result = "Phishing URL"
        elif prediction == 0:
            analysis_result = "Suspecious"
        else:
            analysis_result = "Legitimate URL"
    except:
        analysis_result = "Suspecious URL"

    result_of_analysis = """<section class="iq-about overview-block-pt iq-hide">
                                    <div class="container">
                                        <div class="row align-items-end">
                                            <div class="col-lg-8 col-md-12">
                                                <div class="about-content">
                                                    <h1 class="text-about iq-tw-6">Result of Your URL : <span class="iq-font-green iq-fw-8">""" + url + """</span></h1>
                                                    <ul class="listing-mark iq-mtb-20 iq-tw-6 iq-font-black">
                                                        <li class="good">""" + analysis_result + """</li>
                                                    </ul>
                                                    <h5 class="iq-mt-20 iq-mb-20" style="color: #65d972;font-size: 16px;">Accuracy : """ + str(
        score) + """</h5>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </section>
                                """
    return result_of_analysis
def getResult(url):

    #model=pickle.load(open(r'trained-model/model_random_forest.pkl','rb'))
    model = pickle.load(
        open(r'trained-model/model_logistic_regression.pkl', 'rb'))

    X_new = []

    X_input = url
    X_new = feature_extraction.generate_data_set(X_input)
    X_new = np.array(X_new).reshape(1, -1)

    try:
        prediction = model.predict(X_new)
        if prediction == -1:
            return "Phishing Website"
        else:
            return "Legitimate Website"
    except:
        return "Phishing Website"
Example #8
0
def predict():
    if request.method == 'POST':
        url = request.form['url']
        print(url)
        X_new = []

        X_input = url
        X_new=feature_extraction.generate_data_set(X_input)
        print(X_new)
        X_new = np.array(X_new).reshape(1,-1)
        print(X_new)


        prediction = model.predict(X_new)
        print(prediction)
        output = prediction[0] 
        print(output)
        if output == 1:
            return render_template('index.html',prediction_text = "Good Url")
        else:
            return render_template('index.html',prediction_text = "Malicious Url")
Example #9
0
def getResult(url):

    #Importing dataset
    data = np.loadtxt("dataset.csv", delimiter=",")

    #Seperating features and labels
    X = data[:, :-1]
    y = data[:, -1]

    #Seperating training features, testing features, training labels & testing labels
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
    clf = rfc()
    clf.fit(X_train, y_train)
    score = clf.score(X_test, y_test)
    print(score * 100)

    #joblib.dump(clf, "randomForest.pkl")

    #pickled_model = joblib.load("randomForest.pkl")

    X_new = []

    X_input = url
    X_new = feature_extraction.generate_data_set(X_input)
    X_new = np.array(X_new).reshape(1, -1)

    try:
        prediction = clf.predict(X_new)
        if prediction == -1:
            print('Phishing URL')
            return "Phishing Url"
        else:
            print('Legitimate URL')
            return "Legitimate Url"
    except:
        return "Phishing Url"
Example #10
0
f = open('data.json', 'r+')
#try:
data = json.load(f)

#except:
#    data = {}
#input url
url = input("Enter url:")

if url in data:
    print(data[url])
    exit()

#checking and predicting
else:
    checkprediction = feature_extraction.generate_data_set(url)
    f1.write(','.join(map(str, checkprediction)))
    checkprediction = np.array(checkprediction).reshape(1, -1)

    try:
        prediction = classifier.predict(checkprediction)
        print(prediction)
        if prediction == -1:
            data[url] = "Phishing Url"
        else:
            data[url] = "Legitimate Url"
    except:
        data[url] = "Phishing Url"

    f.seek(0)
    f.write(json.dumps(data))