python 判断输入的ip和网关是否正确

def ip_panduan(ip_name,panduan):
        ip2=["255","255","255","255"]
        if int(panduan)==0:
                ip1=ip_name
                cut_ip_stip=ip1.split(".")
                if len(cut_ip_stip)!=4:
                        print ("ip is not ok")
                        return 0
                else:
                        for x in range(0,4):
                                if not cut_ip_stip[x].isdigit():
                                        print("you input is wrong")
                                        return 0
                                if int(cut_ip_stip[x]) > int(ip2[x]):
                                        print("please your num is dayu 255")
                                        return 0
        else:
#               print ("you input gw")
                ip1=ip_name
                cut_ip_stip=ip1.split(".")
                if len(cut_ip_stip)!=4:
                        print ("ip is not ok")
                        return 0
                else:
                        for x in range(0,4):
                                if not cut_ip_stip[x].isdigit():
                                        print("you input is wrong")
                                        return 0
                                if int(cut_ip_stip[x]) > int(ip2[x]):
                                        print("please your num is dayu 255")
                                        return 0
def gw_name(ip_name,gw_name):
        gw_cut=gw_name.split(".")
        name_cut=ip_name.split(".")
        if ip_panduan(gw_name,1)==0:
                return 0
        else:
                for x in range(4):
                        if (x<3) and int(name_cut[x])!=int(gw_cut[x]):
                                print ("gw input wrong")
                                print gw_cut[x]
                                return 0
ip_name=raw_input("please input you ip: ")
panduan=raw_input("please input 0 or 1,0 is ip,1 is gw :")
ip_panduan(ip_name,panduan)
gw_n=raw_input("please input gateway: ")
print(gw_name(ip_name,gw_n))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

龙在江湖aa

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值